在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sethvargo/vault-kubernetes-workshop开源软件地址(OpenSource Url):https://github.com/sethvargo/vault-kubernetes-workshop开源编程语言(OpenSource Language):Shell 100.0%开源软件介绍(OpenSource Introduction):Vault Kubernetes Workshop on Google Cloud PlatformPrerequisites & Caveats
00 Install VaultThe first step is to install Vault. To install the Vault binary in the current working directory, run the install script.
This will install Vault using the This represents a "best practices" installation for installing secure software like Vault. By verifying the signature of the SHASUMs and then verifying the SHASUMs themselves, we guarantee both the integrity of the download and ensure the binary has not been tampered with beyond it's original publishing. For added security, you can download and compile Vault yourself from source, but that is out of scope for this workshop. Cloud Shell does not persist things in 01 Enable ServicesBy default, a new Google Cloud project does not have many services enabled. Enable the required services (this only needs to be done once per project):
This will make the necessary calls to enable the enable the right APIs on your project. This process can take some time, but it is idempotent (you can run it multiple times to achieve the same result). 02 Setup StorageVault requires a storage backend to persist its data. This workshop leverages Google Cloud Storage. Vault does not automatically create the storage bucket, so we need to create:
Cloud Storage bucket names must be globally unique across all of Google Cloud. The bucket will be named "${PROJECT}-vault-storage". For security purposes, it is not recommended that other applications or services have access to this bucket. Even though the data is encrypted at rest, it is best to limit the scope of access as much as possible. 03 Setup KMSVault will leverage Google Cloud KMS to encrypt its unseal keys for auto-unsealing and auto-scaling purposes. We must create the KMS key in advance:
04 Create IAM Service AccountIt is a best practice to create a limited, dedicated service account that has only the required permissions. Create a dedicated service account in the project and grant it the most minimal set of permissions, in particular:
05 Create Kubernetes ClusterNext we need to create the Google Kubernetes Engine (GKE) cluster which will run Vault. It is recommended that you run Vault in a dedicated namespace or (even better) a dedicated cluster and a dedicated project. Vault will then act as a service with an IP/DNS entry that other projects and services query.
This will create the cluster and attach the service account created in the previous step to the cluster. It also ensures the cluster has the correct oauth scopes. 06 Create Public IPThis step creates and reserves a regional public IP address. In a future step, we will attach this reserved IP address to a Kubernetes load balancer. For now, we will just reserve the dedicated IP address.
We use a regional IP address instead of a global IP address because global IPs
perform load balancing at L7 whereas regional IP addresses perform load
balancing at L4. Ideally we do not want the load balancer to perform TLS
termination, and let Vault manage TLS, etc. While recent versions of Vault do
support advanced routing like This step is not required if you are comfortable assigning your Vault Kubernetes service an ephemeral IP or will manage it via an external DNS service. 07 Create CertificatesThis is arguably the most complex and nuanced piece of the workshop - generating Vault's certificate authority and server certificates for TLS. Vault can run without TLS, but this is highly discouraged. This step could be replaced with a trusted CA like Let's Encrypt, but that is out of scope for this workshop.
This will create the Certificate Authority ( 08 Create ConfigNext we create the config map and secrets to store our data for our pods. The insecure data such as the storage bucket name and IP address are placed in a configmap. The secure data like the TLS certificates are put in a Kubernetes secret.
09 Deploy VaultThe next step is to actually deploy Vault as a StatefulSet on Kubernetes. The reason we use a StatefulSet is two-fold:
Vault will automatically be initialized and unsealed via the vault-init service. 10 Deploy Load BalancerEven though Vault is deployed, it is not publicly accessible. We need to create a Kubernetes Service Load Balancer to forward from the IP address reserved in the previous steps to the pods we just created.
The load balancer listens on port 443 and forwards to port 8200 on the containers. For production-hardened scenarios, you may want to include firewall rules to limit access to Vault at the network layer. 11 Setup CommsLastly, we need to configure our local Vault CLI to communicate with these newly-created Vault servers through the Load Balancer. Since we used custom TLS certificates, we'll need to trust the appropriate CA, etc. This will:
At this point, the local Vault CLI is configured to communicate with our Vault
cluster. Verify by running
12 Setup Static KVNext we will explore techniques for retrieving static (i.e. non-expiring) credentials from Vault. The kv secrets engine is commonly used with legacy applications which cannot handle graceful restarts or when secrets cannot be dynamically generated by Vault.
This will:
Try reading back the secret by running:
You can also read the data via a request tool like curl.
13 Another ClusterNext we are going to create another Kubernetes cluster. There is no requirement that our Vault servers run under Kubernetes (they could be running on dedicated VMs or as a managed service). It is a best practice to treat the Vault server cluster as a "service" through which other applications and services request credentials. As such, moving forward, the Vault cluster will be treated simply as an IP address. We will not leverage K8S for "discovering" the Vault cluster, etc. To put it another way, completely forget that Vault is running in Kubernetes. If it helps, think that Vault is running in a PaaS like Heroku instead. Next create the Kubernetes cluster where our services will actually run. This is completely separate from the Vault K8S cluster. In fact, on GCP, is it recommended that you run these in completely separate projects. For the purpose of this workshop, we will run them in the same project.
This will provision a new Kubernetes cluster named "my-apps". We will deploy all future apps and services in this cluster. Unlike the previous cluster, this cluster does not attach a service account. 14 Service AccountIn our cluster, services will authenticate to Vault using the Kubernetes auth method. In this model, services present their JWT token to Vault as part of an authentication request. Vault takes that signed JWT token and, using the token reviewer API, verifies the token is authenticated. If the authentication is successful, Vault generates a token and maps a series of configured policies onto the token which is returned to the caller.
This will create a dedicated service account named "vault-auth" and grant that service account the ability to communicate with the token reviewer API. 15 Configure Vault to talk to KubernetesNext we need to configure the Vault cluster to talk to our new Kubernetes cluster ("my-apps"). We will need to give Vault the IP address of the cluster, the CA information, and the service account to use for accessing the token reviewer API.
This process will:
There are other techniques for retrieving some of these values, but leveraging
16 Create KV RoleTypically this process is done by a security team or operations team. We need to configure Vault to map an application or service in Kubernetes to a series of policies in Vault. That way, when an application successfully authenticates to Vault via its JWT token, Vault knows which policies to assign to the response.
This will create a role named "myapp-role" that permits pods in the "default" namespace with the "default" service account to receive a Vault token that has the "myapp-kv-rw" policy attached. 17 Sidecar Static AppThis is one of the most common techniques for injecting Vault secrets into an application.
Verify the app is authenticating and retrieving secrets from Vault:
18 Setup Dynamic CredentialsNext we configure Vault to generate dynamic credentials. Vault can generate many types of dynamic credentials like database credentials, certificates, etc. For this example, we will leverage the GCP secrets engine to dynamically generate Google Cloud Platform CloudSQL MySQL users.
This will:
This process can take up to 10 minutes to complete. 19 Sidecar Dynamic AppIn this example, we follow the same pattern as the static KV secrets, but our sidecar application will pull dynamic credentials from Vault. In this case, we will be creating a database password.
This also configures a command to run which will signal the application when the underlying service account changes. This is important as we need to notify the application (which is not aware of Vault's existence) that it should reload its configuration. Verify the app is authenticating and retrieving secrets from Vault:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论