Skip to content

K8s support - Update Authentication #1

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

Closed
wants to merge 8 commits into from
Closed

Conversation

Bobbins228
Copy link
Owner

@Bobbins228 Bobbins228 commented Jun 28, 2023

Update authentication for Kubernetes

A user can now authenticate using their own k8s config file.
When a user logs in for the first time and there is no config file in the default path ~/.kube/config a new one is created from a template with their credentials.
Logging out removes the most recent username and token from the config file.

If a user tries to log in again the config file is checked for if they have logged in before by searching for the user's server address.
The username and token are appended to the config file.

All methods that used config.load_kube_config() have been updated to check if a user has already specified their own config file so it isn't overriden.

How to test the new authentication methods

git pull https://github.com/Bobbins228/codeflare-sdk.git
git checkout k8s-support
Run poetry build within the codeflare-sdk folder to build your own wheel.
Install the sdk with pip install codeflare_sdk-0.0.0.dev0-py3-none-any.whl
Import the necessary classes.

# Import pieces from codeflare-sdk
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
from codeflare_sdk.cluster.auth import TokenAuthentication, KubeConfigFileAuthentication

Loading a user's own config file

auth = KubeConfigFileAuthentication(
            kube_config_path="/path/to/config"
        )
auth.load_kube_config()

Removing the user's config file (Deletes the file)
auth.remove_config()

Authenticating with token + server

Authenticating with certificate

auth = TokenAuthentication(
    token = "TOKEN",
    server = "SERVER",
    username = "USERNAME",
    skip_tls=False,
    ca_cert_path="path/to/ca_bundle.crt"
)
auth.login()

Authenticating by skipping tls verification

auth = TokenAuthentication(
    token = "TOKEN",
    server = "SERVER",
    username = "USERNAME",
    skip_tls=True
)
auth.login()

Logging out
auth.logout()

@Bobbins228 Bobbins228 closed this Jun 28, 2023
@Bobbins228 Bobbins228 reopened this Jun 28, 2023
@Bobbins228 Bobbins228 closed this Jun 29, 2023
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.

2 participants