Skip to content

feat: Remove AWS key and use ECR passwords for docker login - #171

Open
dhairya-hackerrank wants to merge 1 commit into
ProblemSetters:2404from
dhairya-hackerrank:2404-ecr
Open

feat: Remove AWS key and use ECR passwords for docker login#171
dhairya-hackerrank wants to merge 1 commit into
ProblemSetters:2404from
dhairya-hackerrank:2404-ecr

Conversation

@dhairya-hackerrank

@dhairya-hackerrank dhairya-hackerrank commented Aug 27, 2026

Copy link
Copy Markdown

Summary

Removes the embedded AWS access key/secret from Blackbox’s ECR login flow.

ECR passwords are now supplied by the host through a read-only token handoff directory, instead of being generated inside Blackbox with static AWS credentials.

Changes

  • Adds BLACKBOX_ECR_TOKEN_DIR (default: /run/hackerrank/devops-ecr) and a bounded 30-second wait for the required token files.
  • Adds shared helpers to:
    • read non-empty private-password / public-password files;
    • log Docker in as both root and BLACKBOX_USER_NAME.
  • Uses the host-provided private ECR password as a required dependency: provisioning fails clearly if it is unavailable.
  • Keeps public ECR login best-effort for backward compatibility; a failure only warns because some existing questions still pull public images.
  • Mounts the token directory read-only into spawned check containers across the abstract, AWS, Ansible AWS, and Terraform AWS flows, so nested Docker/Kubernetes provisioning can authenticate too.
  • Retains awscli provisioning temporarily because AWS-related modules still rely on its LocalStack shim and placeholder environment setup; it is no longer used to obtain ECR credentials.
  • Documents the new token helper behavior and failure modes.

Reviewer notes

The host must publish complete token files atomically in the configured directory. Blackbox reads the token before logging out any baked Docker credential, avoiding a misleading expired-token pull failure when the host handoff is missing.

Signed-off-by: DhairyaMajmudar <dhairya.opensource@gmail.com>
@sangamcse
sangamcse requested review from sangamcse and ya-developer and removed request for sangamcse August 28, 2026 10:29

@sangamcse sangamcse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhairya-hackerrank, can you check these comments? Rest looks good

Comment on lines +319 to +322
{
docker logout "$registry" &>/dev/null
sudo -u "$BLACKBOX_USER_NAME" docker logout "$registry" &>/dev/null
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we still require this? It might have come due to our startup script trying to login docker, which might have raced with Blackbox trying to logic docker.

Comment on lines +345 to +348
# TODO: the ECR login itself no longer needs the AWS CLI, but this call is what
# installs the localstack endpoint shim and the placeholder AWS_* environment the
# "aws", "aws-stdl", "ansible-aws" and "terraform-aws" modules rely on, and none of
# them provisions "awscli" itself. Remove once they declare the dependency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO: the ECR login itself no longer needs the AWS CLI, but this call is what
# installs the localstack endpoint shim and the placeholder AWS_* environment the
# "aws", "aws-stdl", "ansible-aws" and "terraform-aws" modules rely on, and none of
# them provisions "awscli" itself. Remove once they declare the dependency.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +292 to +299
# Logs in to a Docker registry with a password from the host credential handoff
#
# The token is read before any existing credential is dropped. The machine image
# bakes a "docker login" at build time whose token is hours or days stale, so it
# cannot be trusted once the handoff is the credential source, but discarding it
# before a fresh token is in hand would turn a missing handoff into
# "Your authorization token has expired" on a later pull, hiding the real cause.
# On a successful read the baked credential is dropped for both users.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it short.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +252 to +257
# Reads an ECR docker-login password from the host credential handoff
#
# ECR credentials are refreshed out of band on the host and published atomically
# under "$BLACKBOX_ECR_TOKEN_DIR" (write to a temporary file, then rename), so a
# reader here never observes a partially written password. The publish can lag
# behind the start of a provision, hence the bounded wait.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cut this short

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants