This project builds a Docker image with an API able to retrieve authorization tokens from AWS APIs.
It is aimed at being used in GitLab CI as a [service container](https://docs.gitlab.com/ee/ci/services/)
in order to decouple the image of your jobs and the way AWS authorization tokens are retrieved.
## API usage
### The notion of `env_ctx`
This API supports the notion of `env_ctx`. It can either be guessed contextually (read next chapter), or explicitly passed in all API endpoints.
The `env_ctx` is used when retrieving a configuration value - say `SOME_SECRET`:
* the value will first be readed from `$AWS_{env_ctx}_SOME_SECRET`,
* if not valuated, will fallback to `$AWS_SOME_SECRET`.
This is therefore a way of specializing configuration variables to a specific context.
#### How is guessed `env_ctx`?
When not explicitly set, `env_ctx` is automatically guessed based on [GitLab predefined variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html):
| `$CI_COMMIT_REF_NAME` | `env_ctx` value |
| --------------------- | --------------- |
| `master` or `main` | **PROD** if `$CI_JOB_STAGE` is one of `publish`, `infra-prod`, `production`, `.post`<br/>**STAGING** otherwise |
| `develop` | **INTEG** |
| _any other branch_ | **REVIEW** |
### Supported authentication methods
The API supports two authentication methods:
1. basic authentication with AWS access key ID & secret access key,
2. or [federated authentication using OpenID Connect](https://docs.gitlab.com/ee/ci/cloud_services/aws/).
#### Basic authentication
If you wish to use this authentication method, you'll have pass the AWS access key ID & secret access key as environment variables.
The API is able to segregate variables per environment type.
The expected environment variables are `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` (with their specialized values depending on the `env_ctx`).
#### Federated authentication using OpenID Connect
The API supports [OpenID Connect to retrieve temporary credentials](https://docs.gitlab.com/ee/ci/cloud_services/aws/).
If you wish to use this authentication mode, please apply carefully the instructions from the GitLab guide, then provide the following variables to the API:
*`AWS_JWT` for the JWT token (using GitLab [ID Tokens](https://docs.gitlab.com/ee/ci/secrets/id_token_authentication.html)),
*`AWS_OIDC_ROLE_ARN`: the configured role ARN.
You may specialize those variables for the current `env_ctx`.
### API endpoint: GET ECR token
This API retrieves an [ECR authorization token](https://docs.aws.amazon.com/AmazonECR/latest/APIReference/API_GetAuthorizationToken.html).