Code Monkey home page Code Monkey logo

hyper-kube-config's Introduction

hyper-kube-config

Python Tests

PyPI version

hyper-kube-config - Provides a secure Serverless API to store and retrieve Kubernetes cluster config credentials. hyper-kube-config leverages AWS Secrets Manager for storing credential information. Included is a kubectl plugin to interface with hyperkube API.

You can also set cluster's status and retrieve this information. Useful in CI/CD pipelines when trying to pull access to particular cluters without needing to know their names, just their environments.

It requires a configuration file. See hyperkube-config.yaml.example for layout.

hyper-kube-config

Install hyperkube kubectl plugin

pip3 install hyper-kube-config 

Setup ~/hyperkube-config.yaml file

The default locations for the config file is ~/hyperkube-config.yaml. You can also place the config file at a different location and pass the location as a command line option -c <hyper-kube-config-location> or --config <hyper-kube-config-location>

Post cluster and creds to hyperkube store

kubectl hyperkube add --k8s-config ~/.kube/config

Remove cluster and creds

kubectl hyperkube remove --cluster-to-remove 'k8s-cluster-example.cloud' 

Get user creds and merge it with existing ~/.kube/config

# for single cluster
kubectl hyperkube get --cluster cloud-infra.cloud -m

Get user creds multiple clusters and merge them with existing ~/.kube/config

kubectl hyperkube get \
  --cluster cloud-infra.cloud \
  --cluster bar-cluster.cloud \
  --cluster baz-cluster.com -m

Get creds for all clusters and merge it with existing ~/.kube/config

kubectl hyperkube get-all -m

List clusters

kubectl hyperkube list

Store and Associate SSH PEM and CA private key with Cluster

Store SSH Pem

kubectl hyperkube add-pem --pem ~/.ssh/my-cluster.pem 

Get Stored SSH Pem

kubectl hyperkube get-pem --cluster my-cluster.net

Store Add CA Private Key

kubectl hyperkube add-ca-key --ca-key ca-key-file.key --cluser my-cluster.net

Set Cluster Status and/or Environment References

# Set arbitrary status string and environment reference for given cluster
kubectl hyperkube set-cluster-status --cluster my-cluster.net --status active --environment stage

Get Cluster Status for Environment

# Returns list of clusters that are active for prod environment
kubectl hyperkube get-cluster-status --status active --environment prod

Requirements

  • Serverless - Serverless Framework
  • serverless-python-requirements plugin. Uses Docker and Pip to package a newer vesion of Boto3 for AWS Lambda function use. AWS Lambda boto3 version by default doesn't have AWS Secrets Manager support for tags.
  • click - for hyperkube kubectl plugin
  • kubectl - version 1.12 or higher recommended for stable plugin support.

Deploying Serverless API

Choose authentication method

API Key

Example Serverless Config for API Key Authentication

This config should work out of the box. Feel free to copy to serverless.yml and deploy

IAM Authentication

Example Serverless Config for IAM Authentication

This configuration will require you to add IAM roles to the allowed principal section. These roles are managed outside the scope of this project.

See the section that has:

  resourcePolicy:
    - Effect: Allow
      Principal:
        AWS:
          - arn:aws:iam::{{otherAWSAccountID}}:root
          - arn:aws:iam::{{otherAWSAccountID}}:user/{{otherAWSUserName}}
          - arn:aws:iam::{{otherAWSAccountID}}:role/{{otherAWSRoleName}}

replace with your roles you would like to grant access.

sls deployment
pipenv install
pipenv shell
sls deploy \
  --stage dev \
  --product k8s \
  --owner [email protected] \
  --team myteam \
  --environment dev

This will launch your hyperkube API. Capture the API URL, api key and stage for your hyperkube.yaml configuration. The kubectl hyperkube commands will leverage the config to interact with your stored k8s configs.

Serverless will launch an AWS API Gateway to handle API requests forwardered to AWS Lambda functions. A Dynamodb table is configured to store non-senstative cluster config details, while sensative information in uploaded configs (passwords and certs) is stored in AWS Secrets Manager.

Testing for lint errors on your local machine

  1. Install Test Dependencies
pip install -U -r tests/requirements.txt
  1. Run flake8 to check for lint errors
flake8 *.py tests cli/kubectl-hyperkube
  1. Run unit tests
python -m unittest discover -s tests/ -p "*.py"

hyper-kube-config's People

Contributors

dependabot[bot] avatar emirot avatar kcmartin avatar rajakshay avatar sepulworld avatar swarupdonepudi avatar twonds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hyper-kube-config's Issues

Generate and save new k8s users

Generate and save new k8s users

Leverage cluster CA cert to create new users with certs of their own. They are to be stored in in hyper-kube along side cluster creds and retrieved via kubectl plugin.

I think we should have the role and role binding steps for k8s users handled outside of hyper-kube for now.

Setting cluster status to active without passing --environment does not return error

When I ran the command to set cluster status to active without passing the environment, the call returns a "Setting cluster status active" message but does not really set the cluster to active. But when I pass --environment dev I see the following output.

Setting cluster environment to dev
Setting cluster status active

Does not work(which is great): kubectl hyperkube set-cluster-status --status active --cluster <cluster-fqdn>
Works: kubectl hyperkube set-cluster-status --status active --cluster <cluster-fqdn> --environment <cluster-env>

Not working version should display an error message to the user.

Proper exit code for cluster that doesn't exist

$ kubectl hyperkube -c ~/hyperkube.yaml get --cluster clutster-that-is-nt-there.megacluster.net
{'message': 'Unable to process cluster config for clutster-that-is-nt-there.megacluster.net, '
            'confirm cluster is in list endpoint output'}

should exit non-zero

Do not return the cluster credentials when uploading a kubeconfig that already exists. Only return error message

If the kubeconfig already exists on hyperkube, and I try to re-upload it, it responds with 2 things:

  1. The kubeconfig
  2. The error message: {'message': 'Cluster cluster-name already exists'}

This is usually not an expected operation, but, I came across this while testing kubeconfig upload and download and re-trying those operation.

My problem is that I want to display this error message on failure, but, I do not want to display the kubeconfig. Also, the user asked to upload the kubeconfig, and not download it.

If I send the response to dev/null, I lose the error message as well. Would have been easier to handle this in code, but, unfortunately, I am using bash.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.