#ci #credentials #oidc #ambient #systems #detection #token

ci-id

Ambient OIDC credentials detection on CI systems

6 releases

0.3.0 Dec 3, 2024
0.2.1 Nov 5, 2024
0.1.2 Oct 29, 2024

#644 in Authentication

Download history 343/week @ 2024-10-28 235/week @ 2024-11-04 4/week @ 2024-11-18 156/week @ 2024-12-02 14/week @ 2024-12-09

174 downloads per month
Used in ci-id-bin

Apache-2.0

24KB
492 lines

Ambient credentials detection for CI systems

CI badge

ci-id provides easy access to ambient OIDC credentials in CI systems.

use ci_id::{detect_credentials, CIIDError};

fn main() -> Result<(), CIIDError>  {
    let token = detect_credentials(Some("myaudience"))?;
    print!("Ambient OIDC token detected: {}", token);
    Ok(())
}

See ci-id-bin crate for a simple CLI wrapper.

ci-id is based on id, a similar Python project.

Supported environments

Currently supported environments are:

  • GitHub Actions
  • GitLab CI/CD
  • CircleCI
  • Buildkite

See documentation for details on what configuration each of these environments needs.

License

ci-id is licensed under the Apache 2.0 License.


lib.rs:

ci-id provides easy access to ambient OIDC credentials in CI systems like GitHub Actions.

match ci_id::detect_credentials(Some("my-audience")) {
    Ok(token) => println!("{}", token),
    Err(e) => eprintln!("{}", e)
}

Environment specific setup

Typically the CI environment needs to allow OIDC identity access.

GitHub Actions

Workflow must be given the permission to use the workflow identity:

permissions:
    id-token: write

GitLab Pipelines

An ID token must be defined in the pipeline:

id_tokens:
    MY_AUDIENCE_ID_TOKEN:
        aud: my-audience

The ID token name must be based on the audience so that token name is <AUD>_ID_TOKEN where <AUD> is the audience string sanitized for environment variable names (uppercased and all characters outside of ascii letters and digits are replaced with "_").

CircleCI

No configuration is needed.

Buildkite

No configuration is needed.

Dependencies

~6–18MB
~251K SLoC