Vault Basic Setup: различия между версиями

Материал из noname.com.ua
Перейти к навигацииПерейти к поиску
Строка 29: Строка 29:
 
</PRE>
 
</PRE>
   
  +
Файл с описанием ACL
   
 
<PRE>
 
<PRE>
 
cat acl.tf
 
cat acl.tf
 
</PRE>
 
</PRE>
  +
 
<PRE>
 
<PRE>
 
variable "consul_datacenter" {
 
variable "consul_datacenter" {
Строка 108: Строка 110:
 
}
 
}
   
  +
Инициализировать терраформ и применить ACL
 
 
<PRE>
 
<PRE>
 
terraform init
 
terraform init
Строка 114: Строка 116:
   
 
<PRE>
 
<PRE>
  +
terraform apply -auto-approve
  +
</PRE>
  +
* Вывод (все токены для примера)
  +
<PRE>
  +
Changes to Outputs:
  +
+ consul_acl_token_secret_id = (sensitive value)
  +
+ consul_token_for_vault_server_accessor_id = (sensitive value)
  +
consul_acl_policy.vault_policy: Creating...
  +
consul_acl_policy.vault_policy: Creation complete after 0s [id=6746941f-5928-65e9-76f1-9653b294ccac]
  +
consul_acl_role.vault_role: Creating...
  +
consul_acl_role.vault_role: Creation complete after 0s [id=5e56be99-8a8a-865e-50cc-dfa512051d03]
  +
consul_acl_token.vault_token: Creating...
  +
consul_acl_token.vault_token: Creation complete after 0s [id=5a4ae5cd-8391-f735-e067-4404d859448b]
  +
data.consul_acl_token_secret_id.vault_token: Reading...
  +
data.consul_acl_token_secret_id.vault_token: Read complete after 0s [id=5a4ae5cd-8391-f735-e067-4404d859448b]
  +
  +
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
  +
  +
Outputs:
 
</PRE>
 
</PRE>

Версия 15:04, 4 февраля 2022


Установка и базовая настройка Hashicorm Vault

Consul

Базовая настойка Vault

Устновка

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install vault

Подготовка Consul

Есть разные способы - тут привожу пример с использованием терраформ

export CONSUL_TOKEN="4f6037ed-5f62-5463-d165-cbb984791ef1"
  • Установить терраформ (если не установлен)
apt install terraform

Файл с описанием ACL

cat acl.tf
variable "consul_datacenter" {
    type = string
    default = "kilda-fred"
}
provider "consul" {
  address    = "http://127.0.0.1:8500"
  datacenter = var.consul_datacenter
}
resource "consul_acl_policy" "vault_policy" {
  name        = "vault_policy"
  datacenters = [var.consul_datacenter]
  rules       = <<-RULE
    {
        "key_prefix": {
            "kilda-fred-vault/": {
                "policy": "write"
            }
        },
        "node_prefix": {
            "": {
              "policy": "write"
            }
        },
        "service": {
            "vault": {
                "policy": "write"
            }
        },
        "agent_prefix": {
            "": {
                "policy": "write"
            }
        },
        "session_prefix": {
            "": {
                "policy": "write"
            }
        }
    }
    RULE
}

resource "consul_acl_role" "vault_role" {
    name = "vault_role"
    description = "Role assignet to the Hasicorp Vault service"
    policies = [
        consul_acl_policy.vault_policy.id
    ]
    service_identities {
        service_name = "vault"
    }
}
resource "consul_acl_token" "vault_token" {
    description = "Token for Vault Server"
    roles = [
        consul_acl_role.vault_role.name
    ]
    local = true
}

data "consul_acl_token_secret_id" "vault_token" {
    accessor_id = consul_acl_token.vault_token.accessor_id
}

output "consul_acl_token_secret_id" {
    value = data.consul_acl_token_secret_id.vault_token.secret_id
    sensitive = true
}

output "consul_token_for_vault_server_accessor_id" {
    value = consul_acl_token.vault_token.accessor_id
    sensitive = true
}

Инициализировать терраформ и применить ACL
<PRE>
terraform init
terraform apply -auto-approve
  • Вывод (все токены для примера)
Changes to Outputs:
  + consul_acl_token_secret_id                = (sensitive value)
  + consul_token_for_vault_server_accessor_id = (sensitive value)
consul_acl_policy.vault_policy: Creating...
consul_acl_policy.vault_policy: Creation complete after 0s [id=6746941f-5928-65e9-76f1-9653b294ccac]
consul_acl_role.vault_role: Creating...
consul_acl_role.vault_role: Creation complete after 0s [id=5e56be99-8a8a-865e-50cc-dfa512051d03]
consul_acl_token.vault_token: Creating...
consul_acl_token.vault_token: Creation complete after 0s [id=5a4ae5cd-8391-f735-e067-4404d859448b]
data.consul_acl_token_secret_id.vault_token: Reading...
data.consul_acl_token_secret_id.vault_token: Read complete after 0s [id=5a4ae5cd-8391-f735-e067-4404d859448b]

Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs: