-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
149 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/python3 | ||
# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl | ||
# Derived and adapted from https://www.ateam-oracle.com/secure-way-of-managing-secrets-in-oci | ||
|
||
import os,sys,base64,subprocess,re | ||
|
||
import oci | ||
|
||
compartment_id = '${compartment_id}' | ||
region = '${region}' | ||
secret_id = '${secret_id}' | ||
email_address = '${email_address}' | ||
region_registry = '${region_registry}' | ||
tenancy_name = '${tenancy_name}' | ||
username = '${username}' | ||
|
||
signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner() | ||
|
||
identity_client = oci.identity.IdentityClient(config={}, signer=signer) | ||
|
||
secret_client = oci.secrets.SecretsClient(config={'region': region}, signer=signer) | ||
|
||
def read_secret_value(secret_client, secret_id): | ||
response = secret_client.get_secret_bundle(secret_id) | ||
|
||
base64_Secret_content = response.data.secret_bundle_content.content | ||
base64_secret_bytes = base64_Secret_content.encode('ascii') | ||
base64_message_bytes = base64.b64decode(base64_secret_bytes) | ||
secret_content = base64_message_bytes.decode('ascii') | ||
|
||
return secret_content | ||
|
||
try: | ||
secret_content = read_secret_value(secret_client, secret_id=secret_id) | ||
secret_content = re.escape(secret_content) | ||
delsecret = "kubectl -n default delete secret ocirsecret" | ||
os.system(delsecret) | ||
|
||
crtsecret = ("kubectl create secret docker-registry ocirsecret -n default --docker-server=${region_registry} --docker-username=${tenancy_name}/${username} --docker-email=${email_address} --docker-password=%s" % secret_content) | ||
|
||
subprocess.call(["/bin/bash" , "-c" , crtsecret]) | ||
|
||
except Exception as e: | ||
print(e.message) | ||
print("Please check Secret OCID assigned to secret_id variable") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# # Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved. | ||
# # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl | ||
|
||
data "template_file" "secret" { | ||
template = file("${path.module}/scripts/secret.py") | ||
|
||
vars = { | ||
compartment_id = var.oke_identity.compartment_id | ||
region = var.oke_general.region | ||
secret_id = var.oke_ocir.secret_id | ||
email_address = var.oke_ocir.email_address | ||
region_registry = var.oke_ocir.ocir_urls[var.oke_general.region] | ||
tenancy_name = var.oke_ocir.tenancy_name | ||
username = var.oke_ocir.username | ||
|
||
} | ||
count = var.oke_admin.admin_enabled == true && var.oke_admin.admin_instance_principal == true && var.oke_ocir.secret_id != null ? 1 : 0 | ||
} | ||
|
||
resource null_resource "secret" { | ||
triggers = { | ||
secret_id = var.oke_ocir.secret_id | ||
} | ||
connection { | ||
host = var.oke_admin.admin_private_ip | ||
private_key = file(var.oke_ssh_keys.ssh_private_key_path) | ||
timeout = "40m" | ||
type = "ssh" | ||
user = "opc" | ||
|
||
bastion_host = var.oke_admin.bastion_public_ip | ||
bastion_user = "opc" | ||
bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path) | ||
} | ||
|
||
depends_on = [null_resource.write_kubeconfig_on_admin] | ||
|
||
provisioner "file" { | ||
content = data.template_file.secret[0].rendered | ||
destination = "~/secret.py" | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
"chmod +x $HOME/secret.py", | ||
"$HOME/secret.py", | ||
"sleep 10", | ||
"rm -f $HOME/secret.py" | ||
] | ||
} | ||
|
||
count = var.oke_admin.admin_enabled == true && var.oke_admin.admin_instance_principal == true && var.oke_ocir.secret_id != null ? 1 : 0 | ||
} |
Oops, something went wrong.