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

Go back to using authentication token #31

Merged
merged 47 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
625941a
Reserved IP addresses
fmeheust Aug 29, 2023
ed062df
Moved Certificate OCID to Load Balancer configuration, since applicat…
fmeheust Aug 30, 2023
50afadc
Merge commit '97d2dd24a9da35f60f26f036748751a6bb05e20a' into reserved-ip
fmeheust Feb 22, 2024
b17f3f7
Merge remote-tracking branch 'origin/HEAD' into reserved-ip
fmeheust Feb 22, 2024
25f65de
Remove changes that removes port 80
fmeheust Feb 22, 2024
f3f6ed9
open https port when certificate is provided
fmeheust Feb 22, 2024
505931c
Removed certificate changes
fmeheust Feb 22, 2024
ae8a166
undo certificate changes
fmeheust Feb 22, 2024
4fb164a
update load balancer
fmeheust Feb 22, 2024
1704be1
images
fmeheust Feb 22, 2024
d67f18a
moving certificate
fmeheust Feb 23, 2024
4538071
Moved certificate OCID to Network
fmeheust Feb 23, 2024
6273cff
Updated usage instructions
fmeheust Feb 23, 2024
34d31b6
Merge remote-tracking branch 'origin/HEAD' into reserved-ip
fmeheust Feb 23, 2024
091ab9b
Changed condition for load balancer http port
fmeheust Feb 24, 2024
e8df30d
do not show private key
fmeheust Mar 11, 2024
e36d946
use existing auth key
fmeheust Mar 11, 2024
1e35a2d
removed unused file
fmeheust Mar 11, 2024
20afdd4
updated ssh config file
fmeheust Mar 11, 2024
5d87502
do not copy private key file
fmeheust Mar 11, 2024
5ff6e1e
debug ssh
fmeheust Mar 12, 2024
d55f1ce
api key
fmeheust Mar 12, 2024
b8a2bc1
verify ssh error
fmeheust Mar 12, 2024
c0e16c4
debug ssh
fmeheust Mar 12, 2024
4ff666e
ssh debug
fmeheust Mar 12, 2024
fb99438
ssh debug continue
fmeheust Mar 12, 2024
667f3e5
dependencies
fmeheust Mar 12, 2024
19731cf
ssh connection attempts
fmeheust Mar 12, 2024
0ea18ae
corrected connection attempts
fmeheust Mar 12, 2024
7ec3d6d
connection attempts before git checkout
fmeheust Mar 12, 2024
46e3835
added wait
fmeheust Mar 12, 2024
d84b327
change order between api key and repo creation
fmeheust Mar 12, 2024
084009e
updated usage information
fmeheust Mar 13, 2024
52d15c1
removed unused local
fmeheust Mar 13, 2024
5639d31
Added possibility to use existing API key
fmeheust Mar 13, 2024
b2916be
file is base64 encoded
fmeheust Mar 13, 2024
6253a6c
Do not upload existing api key
fmeheust Mar 13, 2024
1b33d91
Updated usage instuctions, made api-key required
fmeheust Mar 13, 2024
4206422
private key
fmeheust Mar 13, 2024
2da8d29
Mistake in api key
fmeheust Mar 13, 2024
c822cfc
merge
fmeheust Mar 13, 2024
5e1fd54
debug private key
fmeheust Mar 13, 2024
4ba4e62
changed order trying to avoid ssh error
fmeheust Mar 14, 2024
91fd9c3
changed key size
fmeheust Mar 14, 2024
1c44157
Going back to auth token
fmeheust Mar 14, 2024
2953d21
Going back to auth token
fmeheust Mar 14, 2024
2defaf7
Merge remote-tracking branch 'origin/HEAD' into reserved-ip
fmeheust Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 4 additions & 63 deletions config-repo.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

# creates the git repo called "config-repo"
resource "oci_devops_repository" "config_repo" {
depends_on = [ oci_identity_api_key.user_api_key ]
name = local.config_repo_name
project_id = local.project_id
repository_type = "HOSTED"
Expand All @@ -17,32 +16,6 @@ resource "oci_devops_repository" "config_repo" {
count = (local.use-image ? 0 : 1)
}

resource "tls_private_key" "rsa_api_key" {
algorithm = "RSA"
rsa_bits = 4096
count = (local.use-image && !var.use_existing_api_key ? 0 : 1)
}

resource "oci_identity_api_key" "user_api_key" {
#Required
key_value = tls_private_key.rsa_api_key[0].public_key_pem
user_id = var.current_user_ocid
count = (local.use-image || var.use_existing_api_key ? 0 : 1)
}

resource "local_file" "api_private_key" {
depends_on = [ tls_private_key.rsa_api_key ]
filename = "${path.module}/api-private-key.pem"
content = (var.use_existing_api_key ? base64decode(var.api_key) : tls_private_key.rsa_api_key[0].private_key_pem)
count = (local.use-image ? 0 : 1)
}

resource "local_file" "ssh_config" {
filename = "${path.module}/ssh_config"
content = data.template_file.ssh_config.rendered
}


# creates necessary files to configure Docker image
# creates the Dockerfile
resource "local_file" "dockerfile" {
Expand Down Expand Up @@ -98,45 +71,13 @@ resource "null_resource" "create_config_repo" {
local_file.wallet,
local_file.self_signed_certificate,
local_file.oci_build_config,
local_file.ssh_config,
local_file.api_private_key,
oci_identity_auth_token.auth_token,
random_password.wallet_password
]

# create .ssh directory
provisioner "local-exec" {
command = "mkdir ~/.ssh"
on_failure = fail
working_dir = "${path.module}"
}

# copy ssh-config
provisioner "local-exec" {
command = "cp ssh_config ~/.ssh/config"
on_failure = fail
working_dir = "${path.module}"
}
provisioner "local-exec" {
command = "chmod 600 ~/.ssh/config"
on_failure = fail
working_dir = "${path.module}"
}

# copy private key
provisioner "local-exec" {
command = "cp api-private-key.pem ~/.ssh/api-private-key.pem"
on_failure = fail
working_dir = "${path.module}"
}
provisioner "local-exec" {
command = "chmod 400 ~/.ssh/api-private-key.pem"
on_failure = fail
working_dir = "${path.module}"
}

# clone new repository
provisioner "local-exec" {
command = "git -c core.sshCommand='ssh -o StrictHostKeyChecking=no' clone ${oci_devops_repository.config_repo[0].ssh_url}"
command = "git clone ${local.config_repo_url}"
on_failure = fail
working_dir = "${path.module}"
}
Expand All @@ -148,13 +89,13 @@ resource "null_resource" "create_config_repo" {
working_dir = "${path.module}"
}

# clone new repository
# clone new repository
provisioner "local-exec" {
command = "git config --global user.name \"${local.service-username}\""
on_failure = fail
working_dir = "${path.module}"
}

# copy config to app directory
provisioner "local-exec" {
command = "cp build_spec.yaml ./${local.config_repo_name}/build_spec.yaml"
Expand Down
7 changes: 0 additions & 7 deletions datasources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ data "template_file" "deploy_script" {
count = var.nb_copies
}

data "template_file" "ssh_config" {
template = "${file("${path.module}/ssh_config.template")}"
vars = {
"user" = local.ssh_login
}
}

data "oci_identity_api_keys" "dbconnection_api_key" {
user_id = var.current_user_ocid
}
Expand Down
15 changes: 13 additions & 2 deletions interface.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ variableGroups:
###APPLICATION_GROUP###
- title: "Stack authentication"
variables:
- use_existing_api_key
- api_key
- use_existing_token
- current_user_token
- use_existing_vault
- new_vault_display_name
- vault_compartment_id
Expand Down Expand Up @@ -260,6 +260,17 @@ variables:
visible:
and:
- use_existing_vault
use_existing_token:
type: boolean
required: true
title: Use existing authentication token
description: This token will be used by the stack to authenticate the user when connecting to the code repository or container registry.
default: true
current_user_token:
type: password
required: true
title: User's authentication token
visible: use_existing_token
###APP_CONFIG###
# FQDN
create_fqdn:
Expand Down
3 changes: 0 additions & 3 deletions ssh_config.template

This file was deleted.

25 changes: 14 additions & 11 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,16 @@ variable "reserved_ip_address" {
default = ""
}

variable "use_existing_api_key" {
variable "use_existing_token" {
type = bool
description = "Create authentication token for current user"
default = false
}

variable "api_key" {
variable "current_user_token" {
type = string
default = "none"
default = ""
sensitive = true
}

locals {
Expand All @@ -431,8 +433,10 @@ locals {
service-username = data.oci_identity_user.current_user.name
# login, tenancy + username (DevOps)
login = "${data.oci_identity_tenancy.tenancy.name}/${local.service-username}"
# ssh login
ssh_login = "${local.service-username}@${data.oci_identity_tenancy.tenancy.name}"
# authentication token
app_auth_token = var.use_existing_token ? var.current_user_token : oci_identity_auth_token.auth_token[0].token
# Authentication token secret
auth_token_secret = oci_vault_secret.auth_token_secret.id
# login, namespace + username (Container Registry)
login_container = "${local.namespace}/${local.service-username}"
# Container registry url
Expand Down Expand Up @@ -467,13 +471,12 @@ locals {
: var.image_path)
# bucket name
bucket_name = "${local.application_name}-bucket"

# dbconnection_api_key_pem = (
# length(data.oci_identity_api_keys.dbconnection_api_key.api_keys) == 0
# ? oci_identity_api_key.dbconnection_api_key[0].key_value
# : data.oci_identity_api_keys.dbconnection_api_key.api_keys[0].key_value
# )
# name of the config repository
config_repo_name = "${local.application_name}-config"
# url of the config repository
config_repo_url = (local.use-image
? ""
: replace(oci_devops_repository.config_repo[0].http_url, "https://", "https://${urlencode(local.login)}:${urlencode(local.app_auth_token)}@"))
# database OCID
database_ocid = (var.use_existing_database ? var.autonomous_database : oci_database_autonomous_database.database[0].id)
# database username
Expand Down
28 changes: 28 additions & 0 deletions vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ resource "oci_kms_key" "app_key" {
count = var.use_existing_vault ? 0 : 1
}

# Create an authentication token for user to connect to repositories
resource "oci_identity_auth_token" "auth_token" {
# provider = oci.home-provider
description = "Authentication token for ${local.application_name}"
user_id = var.current_user_ocid
count = (var.use_existing_token ? 0 : 1)
}

# Secret containing the authentication token
resource "oci_vault_secret" "auth_token_secret" {
depends_on = [
oci_kms_vault.app_vault,
oci_kms_key.app_key
]
#Required
compartment_id = var.use_existing_vault ? var.vault_compartment_id : var.compartment_id
secret_content {
#Required
content_type = "BASE64"

#Optional
content = base64encode(local.app_auth_token)
name = "auth_token_content_${formatdate("MMDDhhmm", timestamp())}"
}
secret_name ="auth_token_secret_${formatdate("MMDDhhmm", timestamp())}"
vault_id = var.use_existing_vault ? var.vault_id : oci_kms_vault.app_vault[0].id
key_id = var.use_existing_vault ? var.key_id : oci_kms_key.app_key[0].id
}

# Secret containing the db user's password
resource "oci_vault_secret" "db_user_password" {
Expand Down