Search code examples
rundeck

Authentication error when using rundeck cli (aka rd)


I'm using rundeck-cli rd on my container. I set

RD_URL=http://localhost:4440/rundeck
RD_USER=myuser
RD_PASSWORD=mypassword

but

when trying to login, I fail to authenticate. I tested the credentials on the web UI successfully

Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: --> GET http://localhost:4440/rundeck/ http/1.1
Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: <-- 302 Found http://localhost:4440/rundeck/ (8ms, 0-byte body)
Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: --> GET http://localhost:4440/user/login http/1.1
Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: <-- 200 OK http://localhost:4440/user/login (19ms, unknown-length body)
Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: --> POST http://localhost:4440/rundeck/j_security_check http/1.1 (33-byte body)
Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: <-- 302 Found http://localhost:4440/rundeck/j_security_check (26ms, 0-byte body)
Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: --> GET http://localhost:4440/rundeck/ http/1.1
Apr 28, 2020 7:26:41 PM okhttp3.internal.platform.Platform log
INFO: <-- 404 Not Found http://localhost:4440/rundeck/ (19ms, unknown-length body)
Exception in thread "main" java.lang.IllegalStateException: Password Authentication failed, expected a successful response.
        at org.rundeck.client.util.FormAuthInterceptor.authenticate(FormAuthInterceptor.java:82)
        at org.rundeck.client.util.FormAuthInterceptor.intercept(FormAuthInterceptor.java:59)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)


Solution

  • You can do that "tuning" the Rundeck official image using docker-compose and Dockerfile.

    Create a directory and put the docker-compose.yml with the following content:

    version: '3'
    services:
      rundeck:
        build:
          context: .
          args:
            IMAGE: ${RUNDECK_IMAGE:-rundeck/rundeck:3.2.6}
        ports:
          - 4440:4440
        links:
          - postgres
        environment:
          RUNDECK_DATABASE_DRIVER: org.postgresql.Driver
          RUNDECK_DATABASE_USERNAME: rundeck
          RUNDECK_DATABASE_PASSWORD: rundeck
          RUNDECK_DATABASE_URL: jdbc:postgresql://postgres/rundeck?autoReconnect=true&useSSL=false
      postgres:
          image: postgres
          expose:
            - 3306
          environment:
            - POSTGRES_USER=rundeck
            - POSTGRES_PASSWORD=rundeck
          volumes:
            - dbdata:/var/lib/postgresql/data
    volumes:
        dbdata:
    
    

    And put this Dockerfile in the same directory with the following content:

    ARG IMAGE
    FROM ${IMAGE}
    
    RUN sudo apt-get update \
      && sudo echo "deb https://dl.bintray.com/rundeck/rundeck-deb /" | sudo tee -a /etc/apt/sources.list \
      && sudo curl "https://bintray.com/user/downloadSubjectPublicKey?username=bintray" > /tmp/bintray.gpg.key \
      && sudo apt-key add - < /tmp/bintray.gpg.key \
      && sudo apt-get -y install apt-transport-https  \
      && sudo apt-get -y update \
      && sudo apt-get -y install rundeck-cli
    
    ENV RD_AUTH_PROMPT false
    # or your defined host
    ENV RD_URL http://localhost:4440
    ENV RD_USER admin
    ENV RD_PASSWORD admin
    
    

    To create all environment do: docker-compose up

    Enter to your container with: docker exec -it your_rundeck_container bash

    And test RD-CLI doing: rd run -j YourJobName -p YourProjectName

    You can see the result and execution on GUI.

    Here you have a lot of examples to do anything with Rundeck and Docker.