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

Use an AWS deployer user to fetch kubernetes credentials in our deployer #673

Merged
merged 7 commits into from
Sep 14, 2021
14 changes: 14 additions & 0 deletions .github/workflows/deploy-hubs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- 2i2c
- cloudbank
- carbonplan
- farallon
# Uncomment openscapes once a deployer user is created in openscapes AWS land
# - openscapes
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
- meom-ige
- pangeo-181919
- pangeo-hubs
Expand Down Expand Up @@ -81,6 +84,17 @@ jobs:
(steps.config_files.outputs.hub_config == 'true')
uses: mdgreenwald/mozilla-sops-action@v1

- name: Setup kops
if: |
(steps.base_files.outputs.files == 'true') ||
(steps.config_files.outputs.hub_config == 'true')
run: |
curl -Lo kops https://github.com/kubernetes/kops/releases/download/$KOPS_VERSION/kops-linux-amd64
chmod +x kops
sudo mv kops /usr/local/bin/kops
env:
KOPS_VERSION: "v1.21.1"

- name: Deploy ${{ matrix.cluster_name }}
if: |
(steps.base_files.outputs.files == 'true') ||
Expand Down
10 changes: 7 additions & 3 deletions config/hubs/farallon.cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: farallon
provider: kubeconfig
kubeconfig:
file: secrets/farallon.yaml
provider: aws
aws:
key: secrets/farallon.json
clusterType: kops
clusterName: farallonhub.k8s.local
region: us-east-2
stateStore: s3://2i2c-farallon-kops-state
hubs:
- name: staging
domain: staging.farallon.2i2c.cloud
Expand Down
12 changes: 12 additions & 0 deletions config/hubs/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,23 @@ properties:
type: string
description: |
The AWS region the cluster is in.
stateStore:
type: string
description: |
A dedicated S3 bucket for kops to use in order to store the state
(and the representation) of your of your kops cluster.
required:
- key
- clusterType
- clusterName
- region
if:
properties:
clusterType:
const: kops
then:
required:
- stateStore
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
hubs:
type: array
description: |
Expand Down
23 changes: 17 additions & 6 deletions deployer/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def auth_aws(self):
"""
Reads `aws` nested config and temporarily sets environment variables
like `KUBECONFIG`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`
before trying to authenticate with the aws eks update-kubeconfig command.
before trying to authenticate with the `aws eks update-kubeconfig` or
the `kops export kubecfg --admin` commands.

Finally get those environment variables to the original values to prevent
side-effects on existing local configuration.
Expand All @@ -157,6 +158,9 @@ def auth_aws(self):
cluster_name = config['clusterName']
region = config['region']

if cluster_type == 'kops':
state_store = config['stateStore']

with tempfile.NamedTemporaryFile() as kubeconfig:
orig_kubeconfig = os.environ.get('KUBECONFIG', None)
orig_access_key_id = os.environ.get('AWS_ACCESS_KEY_ID', None)
Expand All @@ -176,11 +180,18 @@ def auth_aws(self):

os.environ['KUBECONFIG'] = kubeconfig.name

subprocess.check_call([
'aws', 'eks', 'update-kubeconfig',
f'--name={cluster_name}',
f'--region={region}'
])
if cluster_type == 'kops':
subprocess.check_call([
'kops', 'export', 'kubecfg', '--admin',
f'--name={cluster_name}',
f'--state={state_store}'
])
else:
subprocess.check_call([
'aws', 'eks', 'update-kubeconfig',
f'--name={cluster_name}',
f'--region={region}'
])

yield
finally:
Expand Down
27 changes: 27 additions & 0 deletions secrets/farallon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"AccessKey": {
"UserName": "ENC[AES256_GCM,data:xzejx3ekJ3o=,iv:6pkDM1SlOUZam95khZZsRkszGpf8rzE87ZZFTYfPuNA=,tag:TYF7ctbZ3szuY88kA8MyCg==,type:str]",
"AccessKeyId": "ENC[AES256_GCM,data:baIaSl6LkHTPI6VlIDFU/vhLjHI=,iv:lS1kSvvyB0BCnJ2ROt5ZYqKwRHD5+8PGttyrJRrfNt4=,tag:aATT82STHnqA0gJ18Z6h1w==,type:str]",
"Status": "ENC[AES256_GCM,data:dITKVJJU,iv:zNPAZiM9WlBGFcqTtgYZMCIUYFLGJeIkgnolyL70paU=,tag:y5dsK27jgopRA4YTjFeBTw==,type:str]",
"SecretAccessKey": "ENC[AES256_GCM,data:dv1lLpX+oNckM99jq9XyNDtmvatshvw0vG1R7um3eSWAAK5mhR8lPQ==,iv:vQijh5x9aXKkvwGtC+tz4K7c/2cC+4RS7ZhuR1nH8aE=,tag:DUVVUWjMQVzQ1+COT3gZjQ==,type:str]",
"CreateDate": "ENC[AES256_GCM,data:lTRvSgoBvv78lZKaMyo7FFaM1TY=,iv:GCLCdzuNmKebeQ36vFw1j6hLxzBXbauytA+b9rjpXyE=,tag:QQu4b+NFPCbO3VmP8eTo4Q==,type:str]"
},
"sops": {
"kms": null,
"gcp_kms": [
{
"resource_id": "projects/two-eye-two-see/locations/global/keyRings/sops-keys/cryptoKeys/similar-hubs",
"created_at": "2021-09-10T19:47:17Z",
"enc": "CiQA4OM7eADZ6//P01khGg4CZO59PqPjFbWve5/BrnloowSkutESSQC9ZQbLAKgNPACzbKGS+Na1TnvxQ5HfjKGuRpe28hjxPRxLdYtjrFAJS9sLzMpMUOS10chi3N6SWLLbngM0mDIpCpx5nAzCjiI="
}
],
"azure_kv": null,
"hc_vault": null,
"age": null,
"lastmodified": "2021-09-10T19:47:19Z",
"mac": "ENC[AES256_GCM,data:n/hHhm2IdIQOy/s0yyRr9XzRU0sVTLa4VbzqdSWJ91ZtUiGdbBB6sw81lxRFv7x2MXnlGrBVs6QS07urB31QB7ryr1BhRDJeA0tVzceGf6KGmpqih3luWqEEtrtIwQSuqKgNueEQ4zcNmLq7KavfQkijE3MGYnoAudU/FavChFY=,iv:TO/jhfTpM03n71o9Sx/krrCmtuB/qyQg9FFBTdks5ec=,tag:EVg4qv2iP9SFnj0j0q7sIA==,type:str]",
"pgp": null,
"unencrypted_suffix": "_unencrypted",
"version": "3.7.1"
}
}