① Every GitLab CI/CD pipeline has a CI_JOB_JWT_V2 JSON web token in the predefined variables
- Example JWT
{
"namespace_id": "59407538",
"namespace_path": "joetanx",
"project_id": "46285066",
"project_path": "joetanx/aws-cli-demo",
"user_id": "12855715",
"user_login": "joetanx",
"user_email": "joe.tan@cyberark.com",
"pipeline_id": "877636997",
"pipeline_source": "push",
"job_id": "4343330528",
"ref": "main",
"ref_type": "branch",
"ref_path": "refs/heads/main",
"ref_protected": "true",
"jti": "f9fe5035-17f7-4259-b6f9-873fed0f57ea",
"iss": "gitlab.com",
"iat": 1684936926,
"nbf": 1684936921,
"exp": 1684940526,
"sub": "job_4343330528"
}Note
The value of CI_JOB_JWT_V2 is masked on GitLab jobs
To get the value:
② The GitLab runner sends an authentication request to Conjur using REST API to the JWT authenticator URI (https://<subdomain>.secretsmgr.cyberark.cloud/api/authn-jwt/<service-id>)
- The URI for this demo is
https://apj-secrets.secretsmgr.cyberark.cloud/api/authn-jwt/jtan-gitlab
③ Conjur fetches the public key from the GitLab JWKS URI
- The GibLab SaaS JWKS URI is at
https://gitlab.com/-/jwks/ - This JWKS URI is set in the
jwks-urivariable of the JWT authenticator in Conjur so that Conjur knows where to find the JWKS
④ Conjur verifies that the token is legit with the JWKS public key and authenticates application identity
- Conjur identifies the application identity via the
token-app-propertyvariable of the JWT authenticator - The
token-app-propertyvariable is set in Conjur as theproject_pathclaim in this demo - Conjur further verifies the applications details as configured in the
annotationslisted in thehost(application identity) declaration - The annotations can be any claims on the JWT that do not change on a per-run basis, e.g.
namespace_id,namespace_path,project_path
⑤ Conjur returns an access token to the GitLab runner if authentication is successful
⑥ The GitLab runner will then use the access token to retrieve the secrets using REST API to the secrets URI
GitLab free tier entitles 400 units of compute per month to run GitLab SaaS runners
Credit card information is required to use GitLab SaaS runners
The small machine type is the default and consumes compute units at 1 CI/CD minute cost factor rate
The jobs to be run on GitLab uses an AWS Secret Access Key
The IAM role will need to have the permissions for S3 access and access key rotation
jtan/gitlab- policy name, this forms theidentity-pathof the app IDs- applications
joetanx/aws-cli-demo,joetanx/terraform-aws-s3-demoandjoetanx/terraform-aws-s3-cleanupare configured- the
idof thehostcorresponds to thetoken-app-property - annotations of the
hostare optional and corresponds to claims in the JWT token claims - the more specific the annotations/claims configured, the more precise and secure the application authentication
- the
- the host layer is granted as a member of the
vault/jtan/delegation/consumersgroup to authorize access to the AWS secret access key synchronized from Privilege Cloud
-
Configures the JWT authenticator (https://docs.cyberark.com/Product-Doc/OnlineHelp/ConjurCloud/Latest/en/Content/Operations/Services/cjr-authn-jwt-uc.htm)
-
Defines the authenticator webservice at
authn-jwt/jtan-gitlab- The format of the authenticator webservice is
authn-jwt/<service-id>, the<service-id>used in this demo isjtan-gitlab, this is the URI where the GitLab pipeline will authenticate to.
- The format of the authenticator webservice is
-
Defines the authentication variables: how the JWT Authenticator gets the signing keys
| Variables | Description |
|---|---|
jwks-uri |
JSON Web Key Set (JWKS) URI. For GitLab this is https://gitlab.com/-/jwks/. |
token-app-property |
The JWT claim to be used to identify the application. This demo uses the project_path claim from GitLab. |
identity-path |
The Conjur policy path where the hosts are defined in Conjur policy. The hosts in gitlab-hosts.yaml are created under jtan/gitlab, so the identity-path is data/jtan/gitlab. |
issuer |
URI of the JWT issuer. This is the GitLab URL. This is included in iss claim in the JWT token claims. |
- Defines
consumersgroup - applications that are authorized to authenticate using this JWT authenticator are added to this group - Defines
operatorsgroup - users who are authorized to check the status of this JWT authenticator are added to this group
Login to Conjur:
conjur init -u https://<subdomain>.secretsmgr.cyberark.cloud/api
conjur login -i <username> -p <password>Download and load the Conjur policies:
curl -sLO https://github.com/joetanx/cjc-gitlab/raw/main/authn-jwt-gitlab.yaml
curl -sLO https://github.com/joetanx/cjc-gitlab/raw/main/gitlab-hosts.yaml
conjur policy load -b conjur/authn-jwt -f authn-jwt-gitlab.yaml
conjur policy load -b data -f gitlab-hosts.yamlEnable the JWT Authenticator:
conjur authenticator enable --id authn-jwt/jtan-gitlabPopulate the variables:
conjur variable set -i conjur/authn-jwt/jtan-gitlab/jwks-uri -v https://gitlab.com/-/jwks/
conjur variable set -i conjur/authn-jwt/jtan-gitlab/token-app-property -v project_path
conjur variable set -i conjur/authn-jwt/jtan-gitlab/identity-path -v data/jtan/gitlab
conjur variable set -i conjur/authn-jwt/jtan-gitlab/issuer -v https://gitlab.comThis project tests retrieval of the AWS secret access key from Conjur
GitLab project name: AWS CLI Demo
☝️ Project name is important! The project path must match the host identity configured in the Conjur policy
4.1.2. Create the main.tf file
There are 2 stages in the pipeline code below:
- Fetch variables from Conjur (using CyberArk GitLab runner image)
- Authenticate to Conjur
authn-jwt/jtan-gitlabusingCI_JOB_JWT_V2 - Retrive AWS credentials
- Pass the credentials to the next stage using
artifacts:,reports:,dotenv:
- Test the AWS credentials
- Run Terraform using
docker.io/hashicorp/terraform:latestimage - Run AWS CLI using
docker.io/amazon/aws-cli:latestimage
cjc-gitlab/aws-cli-demo/.gitlab-ci.yml
Lines 1 to 32 in 9de3485
All jobs passed in the pipeline:
Output for fetch variables job:
Output for Terraform job:
Output for AWS CLI job:
This project demostrates the use of AWS secret access key retrieved from Conjur to create a S3 bucket
GitLab project name: Terraform AWS S3 Demo
☝️ Project name is important! The project path must match the host identity configured in the Conjur policy
4.2.2. Create the demo.txt, main.tf and provider.tf files
There are 2 stages in the pipeline code below:
- Fetch variables from Conjur (using CyberArk GitLab runner image)
- Authenticate to Conjur
authn-jwt/jtan-gitlabusingCI_JOB_JWT_V2 - Retrive AWS credentials
- Pass the credentials to the next stage using
artifacts:,reports:,dotenv:
- Run Terraform to create S3 bucket according to
main.tfusing credentials from Conjur
cjc-gitlab/terraform-aws-s3-demo/.gitlab-ci.yml
Lines 1 to 25 in 49bdde5
Both jobs passed in the pipeline:
Output for fetch variables job:
Output for Terraform job:
This project is used to verify the bucket created from the demo job above
GitLab project name: Terraform AWS S3 Cleanup
☝️ Project name is important! The project path must match the host identity configured in the Conjur policy
There are 3 stages in the pipeline code below:
- Fetch variables from Conjur (using CyberArk GitLab runner image)
- Authenticate to Conjur
authn-jwt/jtan-gitlabusingCI_JOB_JWT_V2 - Retrive AWS credentials
- Pass the credentials to the next stage using
artifacts:,reports:,dotenv:
- Run AWS CLI to get the demo file from the S3 bucket created above using credentials from Conjur
- Manual job to delete the bucket
cjc-gitlab/terraform-aws-s3-cleanup/.gitlab-ci.yml
Lines 1 to 34 in a883932
Both jobs passed in the pipeline (manual job is pending manual activation):
Output for fetch variables job:
Output for AWS CLI job:
Proceed to run the last job to delete bucket:
Output for delete bucket job:
Activities in Conjur Cloud can be viewed on CyberArk Audit where details of the action (e.g. authenicate, fetch) and the host identities are recorded



























