【问题标题】:Rundeck Static Token not loaded when Rundeck Service is startedRundeck Service 启动时未加载 Rundeck Static Token
【发布时间】:2023-04-04 14:47:01
【问题描述】:

我认为我的 Rundeck 没有加载我的 tokens.properties 文件。我在加载的 service.log 上看不到它。 Here is a screenshot of the log

这就是为什么当我重新启动服务或服务器时,触发 Rundeck API 的计划作业总是出现此错误

{"error":true,"apiversion":35,"errorCode":"api.error.item.unauthorized","message":"Not authorized for action \"Run\" for Job ID 109fd435-765f-4b7a-a547-0c5906c4a1f5"}

为了让它再次正常工作,我每次重新启动 Rundeck 或服务器时都需要生成一个新令牌。我已经在我的 framework.properties

中包含了这一行
rundeck.tokens.file=C:/rundeck/etc/tokens.properties

在我的 tokens.properties 中,它只有 1 行

atrsdk-runner: token_string

我怎样才能使我的令牌永久化?我在这里错过了什么吗,我将如何解决这个问题?谢谢!

【问题讨论】:

    标签: rundeck


    【解决方案1】:

    您需要在tokens.properties 文件中添加角色。我在 Windows 机器上进行了测试,并以这种方式工作:

    1. 停止 Rundeck 服务。

    2. framework.properties文件添加:

    rundeck.tokens.file=C:/rundeck/tokens.properties
    
    1. realm.properties 文件添加(只是用于测试的示例用户):
    bob:bob,admin
    
    1. c:\rundeck\ 路径下创建一个名为tokens.properties 的文件,内容如下(我在行尾添加了角色):
    bob: 12345, admin
    
    1. 启动 Rundeck 服务。

    2. 通过此 API 调用,您可以使用自定义令牌运行作业(检查 rdeck_token 变量,在运行 cURL 的外部 Linux 主机上测试):

    #!/bin/sh
    
    # protocol
    protocol="http"
    
    # basic rundeck info
    rdeck_host="10.0.1.81"
    rdeck_port="4440"
    rdeck_api="36"
    rdeck_token="12345"
    
    # specific api call info
    rdeck_job="91c5b968-166f-4138-9345-580cd624adda"
    
    # api call
    curl -s --location --request POST "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/job/$rdeck_job/run" \
      --header "Accept: application/json" \
      --header "X-Rundeck-Auth-Token: $rdeck_token" \
      --header "Content-Type: application/json"
    

    现在,如果没有在 tokens.properties 文件中定义角色,我会收到您的错误(输出被 jq“美化”):

    {
      "error": true,
      "apiversion": 36,
      "errorCode": "api.error.item.unauthorized",
      "message": "Not authorized for action \"Run\" for Job ID 91c5b968-166f-4138-9345-580cd624adda"
    }
    

    并在tokens.properties文件中定义角色(成功):

    {
      "id": 3,
      "href": "http://10.0.1.81:4440/api/36/execution/3",
      "permalink": "http://10.0.1.81:4440/project/ProjectBOB/execution/show/3",
      "status": "running",
      "project": "ProjectBOB",
      "executionType": "user",
      "user": "bob",
      "date-started": {
        "unixtime": 1603801591299,
        "date": "2020-10-27T12:26:31Z"
      },
      "job": {
        "id": "91c5b968-166f-4138-9345-580cd624adda",
        "averageDuration": 1727,
        "name": "HelloWorld",
        "group": "",
        "project": "ProjectBOB",
        "description": "",
        "href": "http://10.0.1.81:4440/api/36/job/91c5b968-166f-4138-9345-580cd624adda",
        "permalink": "http://10.0.1.81:4440/project/ProjectBOB/job/show/91c5b968-166f-4138-9345-580cd624adda"
      },
      "description": "echo \"hi\"",
      "argstring": null,
      "serverUUID": "2337f5f7-e951-47d2-ba62-f8c02a0bb8df"
    }
    

    还有here Rundeck 上的执行。

    【讨论】:

    • 您好@MegaDrive68k,我尝试在 token.properties 中添加角色,但我仍然收到未经授权的错误。我的 token.properties 现在看起来像这样:atrsdk-runner: token_string,role_1,role_2,role_3 并且 atrsdk-runner 也存在于 realm.properties 中。
    • 感谢您一直以来的帮助 @MegaDrive68k。它现在正在工作。我在角色中有错字,因为我仍然得到 403,但是当我更正角色的拼写时,它现在工作得很好。
    • 任何时候 roboragi :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    相关资源
    最近更新 更多