Skip to content

Commit 9035160

Browse files
EyalDelareasubatoimchammer01Sharra-writes
authored
Update JFrog GitHub OIDC setup docs (#37596)
Co-authored-by: Ben Ahmady <[email protected]> Co-authored-by: mc <[email protected]> Co-authored-by: Sharra-writes <[email protected]>
1 parent 5936c35 commit 9035160

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

content/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-jfrog.md

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,59 +47,52 @@ To use OIDC with JFrog, establish a trust relationship between {% data variables
4747

4848
## Updating your {% data variables.product.prodname_actions %} workflow
4949

50-
Once you establish a trust relationship between {% data variables.product.prodname_actions %} and the JFrog platform, you can update your {% data variables.product.prodname_actions %} workflow file.
50+
### Authenticating with JFrog using OIDC
5151

5252
In your {% data variables.product.prodname_actions %} workflow file, ensure you are using the provider name and audience you configured in the JFrog Platform.
5353

54-
The following example uses the placeholder `YOUR_PROVIDER_NAME`.
54+
The following example uses the placeholders `YOUR_PROVIDER_NAME` and `YOUR_AUDIENCE`.
5555

5656
```yaml
57-
- name: Fetch Access Token from Artifactory
58-
id: fetch_access_token
59-
env:
60-
ID_TOKEN: ${{ steps.idtoken.outputs.id_token }}
61-
run: |
62-
ACCESS_TOKEN=$(curl \
63-
-X POST \
64-
-H "Content-type: application/json" \
65-
https://example.jfrog.io/access/api/v1/oidc/token \
66-
-d \
67-
"{\"grant_type\": \"urn:ietf:params:oauth:grant-type:token-exchange\", \"subject_token_type\":\"urn:ietf:params:oauth:token-type:id_token\", \"subject_token\": \"$ID_TOKEN\", \"provider_name\": \"YOUR_PROVIDER_NAME\"}" | jq .access_token | tr -d '"')
68-
echo ACCESS_TOKEN=$ACCESS_TOKEN >> $GITHUB_OUTPUT
69-
```
70-
71-
The following example shows part of a {% data variables.product.prodname_actions %} workflow file using cURL.
72-
73-
```yaml
74-
- name: Get ID Token (cURL method)
75-
id: idtoken
76-
run: |
77-
ID_TOKEN=$(curl -sLS -H "User-Agent: actions/oidc-client" -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
78-
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=jfrog-github" | jq .value | tr -d '"')
79-
echo "ID_TOKEN=${ID_TOKEN}" >> $GITHUB_OUTPUT
80-
```
81-
82-
Alternatively, you can set the audience as an environment variable using the `env` context. For more information about the `env` context, see [AUTOTITLE](/actions/learn-github-actions/contexts#env-context).
83-
84-
{% data reusables.actions.oidc-deployment-protection-rules %}
57+
permissions:
58+
id-token: write
59+
contents: read
8560

86-
```yaml
8761
jobs:
8862
build:
8963
runs-on: ubuntu-latest
90-
env:
91-
OIDC_AUDIENCE: 'YOUR_AUDIENCE'
64+
steps:
65+
- name: Set up JFrog CLI with OIDC
66+
id: setup-jfrog-cli
67+
uses: jfrog/setup-jfrog-cli@29fa5190a4123350e81e2a2e8d803b2a27fed15e
68+
with:
69+
JF_URL: ${{ env.JF_URL }}
70+
oidc-provider-name: 'YOUR_PROVIDER_NAME'
71+
oidc-audience: 'YOUR_AUDIENCE' # This is optional
72+
73+
- name: Upload artifact
74+
run: jf rt upload "dist/*.zip" my-repo/
75+
9276
```
9377

94-
Then, in your workflow file, retrieve the value of the variables stored in the `env` context. The following example uses the `env` context to retrieve the OIDC audience.
78+
> [!TIP]
79+
> When OIDC authentication is used, the `setup-jfrog-cli` action automatically provides `oidc-user` and `oidc-token` as step outputs.
80+
> These can be used for other integrations that require authentication with JFrog.
81+
> To reference these outputs, ensure the step has an explicit `id` defined (for example `id: setup-jfrog-cli`).
9582
83+
### Using OIDC Credentials in other steps
9684
```yaml
97-
- name: Get ID Token (using env context)
98-
uses: {% data reusables.actions.action-github-script %}
99-
id: idtoken
85+
- name: Sign in to Artifactory Docker registry
86+
uses: docker/login-action@v3
10087
with:
101-
script: |
102-
const coredemo = require('@actions/core');
103-
let id_token = await coredemo.getIDToken(process.env.OIDC_AUDIENCE);
104-
coredemo.setOutput('id_token', id_token);
88+
registry: ${{ env.JF_URL }}
89+
username: ${{ steps.setup-jfrog-cli.outputs.oidc-user }}
90+
password: ${{ steps.setup-jfrog-cli.outputs.oidc-token }}
91+
```
92+
93+
## Further reading
94+
95+
- [OpenID Connect Integration](https://jfrog.com/help/r/jfrog-platform-administration-documentation/openid-connect-integration) in the JFrog documentation
96+
- [Identity Mappings](https://jfrog.com/help/r/jfrog-platform-administration-documentation/identity-mappings) in the JFrog documentation
97+
- [AUTOTITLE](actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
10598
```

0 commit comments

Comments
 (0)