Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elastic Agent: (docker) jq: command not found #18406

Closed
mtojek opened this issue May 11, 2020 · 13 comments · Fixed by #18408
Closed

Elastic Agent: (docker) jq: command not found #18406

mtojek opened this issue May 11, 2020 · 13 comments · Fixed by #18408
Assignees
Labels
bug Ingest Management:alpha1 Group issues for ingest management alpha1

Comments

@mtojek
Copy link
Contributor

mtojek commented May 11, 2020

I pulled the lastest Docker image for agent and it doesn't start properly:

➜  environments git:(master) docker logs environments_elastic-agent_1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    22  100    22    0     0      2      0  0:00:11  0:00:08  0:00:03     6
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    78  100    22  100    56     11     28  0:00:02  0:00:01  0:00:01    28
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   373  100   331  100    42    328     41  0:00:01  0:00:01 --:--:--   328
/usr/local/bin/docker-entrypoint: line 44: jq: command not found
{"isInitialized":true}{"isInitialized":true}%                                                                                                                                                                   ➜  environments git:(master)
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ingest-management (Team:Ingest Management)

@michalpristas michalpristas added bug elastic-agent Ingest Management:alpha1 Group issues for ingest management alpha1 labels May 11, 2020
@michalpristas michalpristas self-assigned this May 11, 2020
@michalpristas
Copy link
Contributor

same here and it is blocking me so i started working on this

@blakerouse
Copy link
Contributor

Sorry, very surprised this change didn't just work.

Looking at the reason for jq usage, I also wonder if we could just remove it completely. Seems the reason is to get the API key to enroll into Fleet, why not just integrate that directly into the enroll command of agent, instead of using curl and jq?

We should also add an integration test that does a basic smoke test of the agent docker container.

@michalpristas
Copy link
Contributor

i think enroll command should not generate any tokens or setup fleet, it was meant to purely using a token you retrieved from sysadmin make agent capable of communicating with fleet. there was a discussion about this process in some issue about initial trust i will try to find it
@ph correct me please if i'm wrong

@ph
Copy link
Contributor

ph commented May 11, 2020

@michalpristas This is correct, enroll should just make the trust from Agent to the remote Kibana instance.

@blakerouse
Copy link
Contributor

Any reference to that issue so I can read up on it? Seems like it would make the user experience better if we could allow a user to enroll an agent with user/pass.

@nchaulet
Copy link
Member

nchaulet commented May 11, 2020

+1 to move the setup outside the docker agent, it could help to solve that issue too #18347 also I created that PR to avoid the creation of a token and used the one created by default #18365 but I am still using jq

@mtojek
Copy link
Contributor Author

mtojek commented May 11, 2020

Please keep in mind not to remove entirely any important feature like setup or enrollment. We definitely need them in docker setup.

@blakerouse
Copy link
Contributor

Currently the Dockerfile has this:

if [[ -n "${FLEET_ENROLLMENT_TOKEN}" ]] && [[ ${FLEET_ENROLLMENT_TOKEN} == 1 ]]; then
      apikey = "${FLEET_ENROLLMENT_TOKEN}"
    else
      enrollResp=$(curl -X POST  ${KIBANA_HOST:-http://localhost:5601}/api/ingest_manager/fleet/enrollment-api-keys \
        -H 'Content-Type: application/json' \
        -H 'kbn-xsrf: true' \
        -u ${KIBANA_USERNAME:-elastic}:${KIBANA_PASSWORD:-changeme} \
        -d '{"name":"'"${FLEET_TOKEN_NAME:-demotoken}"'","config_id":"'"${FLEET_CONFIG_ID:-default}"'"}')

      local exitCode=$?
      if [ $exitCode -ne 0 ]; then
        exit $exitCode
      fi

      apikey=$(echo $enrollResp | jq -r '.item.api_key')
    fi

    ./{{ .BeatName }} enroll ${KIBANA_HOST:-http://localhost:5601} $apikey -f

I feel like we could condense this into a single command in the agent itself, which will allow proper unit testing and not relying on bash, curl, or jq.

enroll ${KIBANA_HOST:-http://localhost:5601} --username ${KIBANA_USERNAME:-elastic} --password ${KIBANA_PASSWORD:-changeme}

If agent is already enrolled then it would skip the enrollment and we could add a --force to override the skip behavior. We could add this skip logic to the bash entrypoint, but that is just making the bash more complex and prevents the ability to unit test.

@nchaulet
Copy link
Member

@blakerouse in my opinion the agent should only work with kibana host and the enrollment token, and we should never give kibana username and password to the agent

@mtojek in the docker setup can we add another container requirements for the agents, and this container will do the setup and get the enrollment token

@blakerouse
Copy link
Contributor

Being that you still have to pass the username and password to the container for it to enroll unless you have the specific token, I do not see what your preventing by allowing the username and password. The enroll command would just use the username and password to get the token and save the token and not the username or password.

It's already doing the same thing it's just in bash, which is not unit tested or even currently integrated tested.

@ruflin
Copy link
Contributor

ruflin commented May 11, 2020

Perhaps we need a third command here, something like fetch_enrollment_token (better name needed). This might support username/password or API key to be passed in and returns an API key. This means:

  • Instead of having to use bash scripts, we have it on the agent side and can test it
  • We still only support API keys for the final enrollment
  • We could potentially fetch_enrollment_token, enroll and run merge into one additional command to make it simpler for the user.

@nchaulet
Copy link
Member

I still have some concerns about having fetch_enrollment_token in the agent as the goal of enrollment tokens is to not send|use Kibana credentials everywhere too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Ingest Management:alpha1 Group issues for ingest management alpha1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants