Configuring JWT authentication for Jenkins with Teleport Application Access #19056
webvictim
started this conversation in
Show and tell
Replies: 1 comment
|
this is AWESOME - thank you! |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Here is a guide on how to configure JWT authentication with Jenkins so you can pass Teleport usernames and roles through to a Jenkins instance.
Prerequisites
Teleport app access configuration
Here's a rough guide of what the Teleport
app_serviceconfiguration should already look like:This will make Jenkins available on a subdomain of your cluster, i.e.
https://jenkins.teleport.example.comLogging in here should already work correctly assuming you enter the correct username/password for a local Jenkins user. If this does not work correctly, fix it before continuing with this guide.
Example JWT token
This is a rough example of what a decrypted JWT token will look like when sent from Teleport. We will use this example to configure Jenkins appropriately.
{ "aud": [ "http://127.0.0.1:37491" ], "exp": 1667520826, "iat": 1667506428, "iss": "teleport.example.com", "nbf": 1667506418, "roles": [ "access", "editor", "sysadmin", "allow-requests", "allow-user-root", "per-session-mfa", "allow-aws-readonly", "allow-mssql-access", "allow-mysql-access", "allow-postgres-access", "kubernetes-access-eks", "kubernetes-access-gke", "allow-request-approval", "windows-desktop-access", "allow-aws-ec2-fullaccess" ], "sub": "gus@example.com", "username": "gus@example.com" }Configuring Jenkins
Change the settings to match as follows:
Authentication
Teleport-Jwt-Assertionsubroles,https://teleport.example.com/.well-known/jwks.json# replace with your public Teleport URLAuthorization
Set this to "Logged-in users can do anything"
You can change and set permissions this in future after you've proven that users can sign in correctly.
JWKS URL tips
teleport.example.comhere with the public address of your Teleport cluster.jenkins.customer.domain.com, your public URL iscustomer.domain.comtenant.teleport.shhttps://teleport.example.com/.well-known/jwks.jsonin your browser should output a JSON payload similar to this:{"keys":[{"kty":"RSA","alg":"RS256","n":"ohCpCcv7VuvetyzNnFiPw79XMFm27OgJZMup7VSSSMpcRFcZtXkYvHWe_8H6VdKeb0AsnTfKrBKbNFc0h3uulLQq5a7kAJKwwTcS3KrgDfzzctnJkAJylWjYmOsw1VdSdJ_Ci0xjw8_jMFqRTvRt9PZj6bBq-hKTTW9nNNE20uO5wHhB6bqK6Fw26Vi--0-qXXOXGGHiuoZXIEp25MkC27c8eVxDWm8B_DOu_fHT08qeGxYwYnH_Xjm8DCOeEA7lyeQOr4Z66RFTxzXYj3D8Q8EpZeh6DJaKgWidvxkTDAD3IM_Oc6YV2sZ3WAkGe8RIyNQpU-3tGVfQkbstc-lfaw","e":"AQAB"}]}Reloading the page should log you in as your Teleport username (as shown at the top right here)
Troubleshooting
If this does not work and you get "Authentication failed", check your Jenkins server logs. The chances are that you have misconfigured something:
You can edit the JWT auth configuration directly in your
/var/lib/jenkins/config.xmlfile and then restart Jenkins to fix typos or other errors. If you can't fix it, you can get back in by disabling security globally (only on test instances!) and then restarting Jenkins:Edit
config.xmland change<useSecurity>true</useSecurity>to<useSecurity>false</useSecurity>and restart Jenkins.Make sure to re-enable security afterwards!
All reactions