Give developers credential-free Git access
|
To enable the experimental feature that forces a refresh of the personal access token on workspace startup in Eclipse Che, modify the Custom Resource configuration as follows:
|
You can configure OAuth between Che and Git providers, enabling users to work with remote Git repositories:
Refresh OAuth tokens automatically
Git providers issue short-lived OAuth tokens: GitLab, for example, issues tokens that expire after two hours. Che refreshes a token when it reads the token and the provider no longer accepts it, but nothing reads the token of a user who is not interacting with Che at that moment. A workspace that is left running therefore keeps an expired token in its Git credentials, and Git operations such as git pull and git push fail until the user restarts the workspace or authorizes the Git provider again.
To avoid this, you can configure the Che server to refresh OAuth tokens in the background, before they expire. When the feature is enabled, a scheduled job periodically does the following:
-
Reads the running and starting workspaces across the cluster.
-
Determines which Git providers serve the repositories that the devfiles of those workspaces define, so that only the providers that are in use are contacted.
-
Refreshes the OAuth tokens in the namespaces of the owners of those workspaces, and updates the token Secrets and the Git credentials of the running workspaces.
Only tokens that users obtained through the Che OAuth integration are refreshed. Personal access tokens that users configured manually are not affected.
The job is disabled by default. To enable it, configure the spec.gitServices.oauthTokenRefresh section of the CheCluster custom resource.
-
You have an active
kubectlsession with administrative permissions to the destination Kubernetes cluster. See Overview of kubectl. -
You have configured OAuth between Che and at least one Git provider.
-
Enable the automatic OAuth token refresh by patching the
CheClustercustom resource:$ kubectl patch checluster eclipse-che \ --namespace eclipse-che \ --type merge \ --patch '{ "spec": { "gitServices": { "oauthTokenRefresh": { "enabled": true } } } }' -
Optional: Set how often the tokens are refreshed. The default is
600seconds.$ kubectl patch checluster eclipse-che \ --namespace eclipse-che \ --type merge \ --patch '{ "spec": { "gitServices": { "oauthTokenRefresh": { "enabled": true, "periodSec": <period_in_seconds> } } } }'where
<period_in_seconds>is greater than0. Set a period that is shorter than the lifetime of the tokens that your Git provider issues. To disable the job, set theenabledfield tofalserather than setting the period to0.
| Field | Default | Description |
|---|---|---|
|
|
Enables automatic refreshing of OAuth tokens before they expire. |
|
|
How often OAuth tokens are refreshed, in seconds. Must be greater than |
The following limitations apply:
-
Only the providers of the repositories that a workspace devfile defines are taken into account. A repository that a user clones manually in the workspace terminal does not cause the token of its provider to be refreshed.
-
Only tokens of providers that issue refresh tokens are refreshed. A token for which no refresh token is stored is skipped, and the user must authorize the Git provider again when the token expires.
-
Only namespaces that Che manages and whose running workspaces identify a single creator are processed. Tokens in namespaces that are shared by several users are not refreshed. Identities that do not provide a user ID, such as those of some OIDC providers, also prevent the refresh.
-
Tokens that do not expire, such as GitHub OAuth App tokens, are not refreshed.
-
If refreshing one token fails, the remaining tokens are still refreshed, and the failed token is retried on the next run of the job.
-
Verify that the Che server is configured to refresh the tokens:
$ kubectl exec deploy/che \ --namespace eclipse-che -- \ env | grep CHE_OAUTH_TOKEN__REFRESHThe output should report
CHE_OAUTH_TOKEN__REFRESH_ENABLED=trueand the configured period. -
Start a workspace from a repository that is hosted by a Git provider you configured OAuth for, and list the token Secrets in the user namespace:
$ kubectl get secrets \ --namespace <user_namespace> \ -l app.kubernetes.io/part-of=che.eclipse.org,app.kubernetes.io/component=scm-personal-access-token \ -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.metadata.resourceVersion}{"\n"}{end}'Keep the workspace running, and run the command again after the configured period has elapsed. Only running and starting workspaces are inspected, so the tokens are no longer refreshed after the workspace stops. The resource version of the
Secretthat holds the OAuth token changes every time the token is refreshed.