edgexfoundry / edgex-go

EdgeX Golang Services Monorepo | Owner: Core/Support WG
Apache License 2.0
1.34k stars 484 forks source link

Got unauthorized when executing scheduleJob with REST action on security mode #4943

Closed cherrycl closed 1 month ago

cherrycl commented 1 month ago

🐞 Bug Report

Affected Services [REQUIRED]

The issue is located in: support-cron-scheduler ### Is this a regression? No ### Description and Minimal Reproduction [**REQUIRED**] 1. Run command `make run keeper mqtt-bus postgres arm64` under [compose-build](https://github.com/edgexfoundry/edgex-compose/tree/main/compose-builder) to deploy service 2. Generate JWT token by command `make get-token` 3. Create job with REST action ``` [ { "scheduleJob":{ "name":"job_1", "definition":{ "type":"INTERVAL", "interval":"5s", "startTimestamp":{{startTime}}, "endTimestamp":{{endTime}} }, "actions":[ { "type":"REST", "address": "http://edgex-core-data:59880/api/v3/event/age/0", "method": "DELETE" } ], "adminState":"UNLOCKED" }, "apiVersion":"v3" } ] ``` 4. Wait until the job was triggered. ## πŸ”₯ Exception or Error

level=DEBUG ts=2024-10-07T03:30:31.424361618Z app=support-cron-scheduler source=gocron.go:102 msg="Failed to execute the rest action: request failed, status code: 401, err: {\"message\":\"Unauthorized\"}\n"
level=DEBUG ts=2024-10-07T03:30:31.432631753Z app=support-cron-scheduler source=manager.go:312 msg="A new schedule action record with type: REST and status: FAILED was added for job: job_1, record ID: b30b8179-495f-423b-ba5d-a449405b027f, action error: request failed, status code: 401, err: {\"message\":\"Unauthorized\"}\n, Correlation-ID: 00637a9f-7868-49c3-9056-6e256f58a1c6"
## 🌍 Your Environment **Deployment Environment:** Ubuntu2204/arm64 **EdgeX Version [**REQUIRED**]:**Main **Anything else relevant?**
cloudxxx8 commented 1 month ago

@cherrycl to use RESTAction for EdgeX internal API, you have to set injectEdgeXAuth = true Please see the RESTAction schema in the API docs https://docs.edgexfoundry.org/3.2/api/support/Ch-APISupportCronScheduler/

cherrycl commented 1 month ago

Close with invalid issue.