Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to service account after logging into OpenShift Sandbox #3844

Conversation

datho7561
Copy link
Collaborator

The service account will remain authenticated for longer than 15 minutes.

To try this out:

  1. Log into an OpenShift Sandbox cluster using the Login workflow
  2. Run oc whoami. You should see a reference to pipeline, which is the serviceaccount that's being used
  3. The Application Explorer should display you as logged in and work as expected

Closes #3838

Signed-off-by: David Thompson davthomp@redhat.com

@datho7561 datho7561 force-pushed the 3838-use-serviceaccount-on-sandbox branch from a1b219d to 6b56fd9 Compare January 29, 2024 21:06
@datho7561
Copy link
Collaborator Author

@vrubezhny I made the changes you mentioned, specifically:

  • There is a notification box that asks if it's okay to use the service account
  • The existing context is overwritten instead of adding a new one
  • I changed the line wrap settings of the YAML serializer to 120 to avoid >- appearing in the ~/.kube/config

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Attention: 26 lines in your changes are missing coverage. Please review.

Comparison is base (da60441) 32.37% compared to head (8555d78) 45.52%.
Report is 6 commits behind head on main.

Files Patch % Lines
src/openshift/cluster.ts 18.75% 26 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3844       +/-   ##
===========================================
+ Coverage   32.37%   45.52%   +13.15%     
===========================================
  Files          85       85               
  Lines        6505     6532       +27     
  Branches     1349     1352        +3     
===========================================
+ Hits         2106     2974      +868     
+ Misses       4399     3558      -841     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vrubezhny
Copy link
Contributor

vrubezhny commented Jan 31, 2024

@vrubezhny I made the changes you mentioned, specifically:

  • There is a notification box that asks if it's okay to use the service account

✔️

  • The existing context is overwritten instead of adding a new one

❔ The current user is changed to pipeline:

image

So now we have two users: the original one + new pipeline user - both with their tokens set:

- name: vrubezhny/api-sandbox-m3-1530-p1-openshiftapps-com:6443
  user:
    token: sha256~xxxx-xxxx
- name: pipeline
  user:
    token: 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Once we know for sure that the token for my original user (vrubezhny/api-sandbox-m3-1530-p1-openshiftapps-com:6443) will be expired soon - there is no need to keep it here...
So why not just replace this user's token with the pipeline one instead of creating a new pipeline user and switching into it?

  • I changed the line wrap settings of the YAML serializer to 120 to avoid >- appearing in the ~/.kube/config

✅ (There are some tokens that definitely contain more than 120 chars - so it's needed to watch a bit on how the YAML is serialized for those ones, but at the moment I don't see any problems)

@datho7561 datho7561 force-pushed the 3838-use-serviceaccount-on-sandbox branch from 6b56fd9 to 71c1e4f Compare February 1, 2024 16:10
@datho7561
Copy link
Collaborator Author

Okay, I've updated the PR to rewrite the token of the current user instead of creating a new one.

@vrubezhny
Copy link
Contributor

  • I changed the line wrap settings of the YAML serializer to 120 to avoid >- appearing in the ~/.kube/config

✅ (There are some tokens that definitely contain more than 120 chars - so it's needed to watch a bit on how the YAML is serialized for those ones, but at the moment I don't see any problems)

Nope, 120 chars looks like is not enough:

image

@datho7561 datho7561 force-pushed the 3838-use-serviceaccount-on-sandbox branch from 71c1e4f to 5c6c680 Compare February 1, 2024 19:59
Copy link
Contributor

@vrubezhny vrubezhny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall and works like a charm.

The only question is that we probably must use env.KUBECONFIG when compiling a path to the current Kube config

src/openshift/cluster.ts Outdated Show resolved Hide resolved
The service account will remain authenticated for longer than 15
minutes.

To try this out:
1. Log into an OpenShift Sandbox cluster using the Login workflow
2. Run `oc whoami`. You should see a reference to `pipeline`, which is the
   serviceaccount that's being used
3. The Application Explorer should display you as logged in and work as
   expected

Closes redhat-developer#3838

Signed-off-by: David Thompson <davthomp@redhat.com>
Copy link
Contributor

@vrubezhny vrubezhny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me and works like a charm! Thanks!

@vrubezhny vrubezhny merged commit eb06f1c into redhat-developer:main Feb 5, 2024
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Developer Sandbox Login experience enhancement
2 participants