Jenkins
Jenkins can publish without a stored secret. The OpenID Connect Provider plugin gives each job an identity token. Telesphorepo trades it for a publish session.
Set up
Section titled “Set up”- Install the OpenID Connect Provider plugin in Jenkins.
- In Jenkins, add a credential of the kind “OpenID Connect id token”. Set its audience to the URL of your Telesphorepo server, for example
https://repo.acme.com. Give it the IDtelesphorepo-oidc. - An admin opens the Trust policies page and picks the Jenkins preset. The issuer is the Jenkins URL followed by
/oidc, for examplehttps://jenkins.acme.com/oidc. - Add at least one claim that limits which jobs may publish. List the repositories that the policy may publish to.
- Leave the audience empty, or set it to the same text as in the Jenkins credential. Empty means the
base_urlof the server.
See Trust policies for all fields.
Publish with curl
Section titled “Publish with curl”withCredentials([string(credentialsId: 'telesphorepo-oidc', variable: 'OIDC')]) { sh ''' SESSION=$(curl -sSf https://repo.acme.com/api/publish/sessions/oidc \ -H 'Content-Type: application/json' \ -d "{\\"token\\":\\"$OIDC\\",\\"repo\\":\\"releases\\"}") TOKEN=$(echo "$SESSION" | jq -r .token) curl -sSf -u "ci:$TOKEN" -T app-1.0.jar \ https://repo.acme.com/maven/releases/com/acme/app/1.0/app-1.0.jar curl -sSf -X DELETE -u "ci:$TOKEN" \ "https://repo.acme.com/api/publish/sessions/$(echo "$SESSION" | jq -r .id)" '''}The agent needs curl and jq.
Publish with the plugin or extension
Section titled “Publish with the plugin or extension”Both clients read the token from an environment variable.
-
In the Gradle settings, set
oidcTokenEnv. See Gradle plugin.telesphorepo {url = "https://repo.acme.com"oidcTokenEnv = "OIDC"}For Maven, pass
-Dtelesphorepo.oidcTokenEnv=OIDC. See Maven extension. -
Run the build inside
withCredentials, so that the variable is set:Jenkinsfile withCredentials([string(credentialsId: 'telesphorepo-oidc', variable: 'OIDC')]) {sh './gradlew publish'}
When the server cannot reach Jenkins
Section titled “When the server cannot reach Jenkins”The server finds the signing keys of the issuer through discovery. If Jenkins is on a private network, the server cannot do this. Paste the keys into the trust policy instead.
- Download the JWKS of Jenkins from the
jwks_uriin<jenkins url>/oidc/.well-known/openid-configuration. - Paste the JSON into the JWKS field of the trust policy.
- Save. The server checks the pasted keys when you save and uses them instead of discovery.
Update the pasted JWKS when Jenkins rotates its keys.
Gotchas
Section titled “Gotchas”- The
issclaim of the token must equal the issuer of the policy exactly. A different host name or a missing/oidcfails the match. - The
audclaim must equal the audience of the policy. A mismatch fails the exchange. - The server accepts each token once and only if it is at most 10 minutes old. Use a fresh token for each exchange.
- The server accepts RS, ES and PS signatures (256, 384, 512 bits) and EdDSA.
- If you edit or disable a policy, the server ends its open sessions.