Skip to content

Add support for AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE#42

Merged
jesperoman merged 5 commits intomainfrom
fallback_to_token_file
Aug 16, 2025
Merged

Add support for AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE#42
jesperoman merged 5 commits intomainfrom
fallback_to_token_file

Conversation

@jesperoman
Copy link
Copy Markdown
Contributor

In EKS there is no token in env var AWS_CONTAINER_AUTHORIZATION_TOKEN, instead, there's a file containing the token in AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE, this will fall back to getting token from the path referenced in the env var.

@jesperoman jesperoman requested a review from Copilot August 16, 2025 09:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds fallback support for reading AWS container authorization tokens from a file when the token is not available in the environment variable. This addresses EKS scenarios where tokens are stored in files rather than environment variables.

  • Adds a new setting ContainerAuthorizationTokenFile to read token file paths from environment variables
  • Implements fallback logic to read tokens from files when environment variable tokens are unavailable
  • Maintains backward compatibility by trying environment variable tokens first

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Setting.scala Adds new ContainerAuthorizationTokenFile setting to parse file paths from environment variables
CredentialsProvider.scala Implements fallback token reading from files with error handling and fallback logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

case Some(path) =>
for {
s <- readFile(path)
} yield Some(Header.Raw(ci"Authorization", s))
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

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

The token read from file is used directly without trimming whitespace. File-based tokens often contain trailing newlines or whitespace that should be stripped to avoid authentication failures.

Suggested change
} yield Some(Header.Raw(ci"Authorization", s))
} yield Some(Header.Raw(ci"Authorization", s.trim))

Copilot uses AI. Check for mistakes.
} yield Some(Header.Raw(ci"Authorization", s))
case None => none[Header.Raw].pure[F]
}
.recover { case _ => none[Header.Raw] }
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

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

The catch-all exception handler case _ masks all potential errors from file reading operations. This could hide important issues like permission errors or I/O failures. Consider being more specific about which exceptions to handle or at least logging the error.

Suggested change
.recover { case _ => none[Header.Raw] }
.recoverWith { case t => Sync[F].delay { println(s"Error reading container authorization token file: $t"); None } }

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We dont want this library to just print random stuff to stdout, exactly as if failing to read the token directly from env var, we just silently try to get credentials without auth header if this doesn't work.

@jesperoman jesperoman marked this pull request as ready for review August 16, 2025 09:24
@jesperoman jesperoman merged commit aad7248 into main Aug 16, 2025
18 of 19 checks passed
@jesperoman jesperoman deleted the fallback_to_token_file branch August 16, 2025 09:37
@vlovgr vlovgr changed the title Fallback to read token from file Add support for AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE Aug 16, 2025
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