├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── application ├── kustomization.yaml ├── products-api.yaml ├── secrets.yaml └── service-account.yaml ├── clusters └── local │ ├── application-bootstrap-source.yaml │ ├── csi-helm.yaml │ ├── csi-source.yaml │ ├── database-kustomization.yaml │ ├── flux-system │ ├── gotk-components.yaml │ ├── gotk-sync.yaml │ └── kustomization.yaml │ ├── hashicorp-source.yaml │ ├── hashicups-kustomization.yaml │ ├── hashicups-source.yaml │ ├── repository-kustomization.yaml │ ├── vault-helm.yaml │ └── vault-kustomization.yaml ├── database ├── kustomization.yaml └── products-db.yaml ├── gitlab ├── kustomization.yaml └── secrets.yaml ├── set.sh └── vault ├── kubernetes ├── flux-sa.yaml ├── kustomization.yaml ├── product-sa.yaml └── vault-sa.yaml ├── terraform ├── .terraform.lock.hcl ├── auth.tf ├── database.tf ├── gitlab.tf ├── outputs.tf ├── providers.tf └── variables.tf └── values.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | infrastructure/ 2 | unseal.json 3 | backend -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ingress: 2 | helm upgrade --install ingress-nginx ingress-nginx \ 3 | --repo https://kubernetes.github.io/ingress-nginx \ 4 | --namespace ingress-nginx --create-namespace 5 | 6 | flux-bootstrap: 7 | flux bootstrap github \ 8 | --owner=joatmon08 \ 9 | --repository=hashicorp-vault-flux \ 10 | --path=clusters/local \ 11 | --branch=main \ 12 | --personal 13 | kubectl apply -f clusters/local/csi-source.yaml 14 | kubectl apply -f clusters/local/csi-helm.yaml 15 | kubectl apply -f clusters/local/hashicorp-source.yaml 16 | kubectl apply -f clusters/local/vault-serviceaccounts.yaml 17 | kubectl apply -f clusters/local/vault-helm.yaml 18 | kubectl apply -f clusters/local/application-bootstrap-source.yaml 19 | kubectl apply -f clusters/local/database-kustomization.yaml 20 | kubectl apply -f clusters/local/vault-kustomization.yaml 21 | 22 | vault-init: 23 | kubectl exec -ti vault-0 -- vault operator init -key-shares=1 -key-threshold=1 -format=json > unseal.json 24 | kubectl exec -ti vault-0 -- vault operator unseal 25 | 26 | vault-configure: 27 | cd vault/terraform && terraform init 28 | cd vault/terraform && terraform apply 29 | 30 | flux-token: 31 | kubectl apply -f clusters/local/repository-kustomization.yaml 32 | 33 | applications: 34 | kubectl apply -f clusters/local/hashicups-source.yaml 35 | kubectl apply -f clusters/local/hashicups-kustomization.yaml 36 | flux reconcile source git hashicups -n flux-system 37 | 38 | clean: 39 | vault lease revoke -f -prefix hashicups/database/creds/product || true 40 | 41 | flux delete -s kustomization hashicups -n flux-system || true 42 | flux delete -s source git hashicups -n flux-system || true 43 | 44 | flux delete -s kustomization database -n flux-system || true 45 | flux delete -s kustomization repository -n flux-system || true 46 | flux delete -s source git application-bootstrap -n flux-system || true 47 | 48 | vault lease revoke -f -prefix hashicups/flux/data/gitlab || true 49 | cd vault/terraform && terraform destroy -auto-approve || true 50 | 51 | flux delete -s hr vault -n default || true 52 | flux delete -s hr csi -n default || true 53 | kubectl delete pvc --all 54 | 55 | flux delete -s source helm hashicorp -n default || true 56 | flux delete -s source helm secrets-store-csi-driver -n default || true 57 | flux uninstall -s -n flux-system 58 | 59 | helm del ingress-nginx -n ingress-nginx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using HashiCorp Vault with Flux to Inject Secrets 2 | 3 | This is a repository that demonstrates how to use HashiCorp Vault 4 | with Flux. 5 | 6 | Ideally, you should use a [file-based](https://www.vaultproject.io/docs/platform/k8s) approach to injecting 7 | secrets into your applications and omit Kubernetes secrets. 8 | 9 | However, some tools, like Flux, need Kubernetes secrets for setup. 10 | 11 | As a solution, you can use the [Secrets Store CSI driver's Sync as Kubernetes Secret](https://secrets-store-csi-driver.sigs.k8s.io/topics/sync-as-kubernetes-secret.html) 12 | capability with the [Vault CSI provider](https://www.vaultproject.io/docs/platform/k8s/csi). 13 | 14 | This means that the Vault CSI provider will retrieve the secret from Vault and synchronize it to a Kubernetes 15 | secret. 16 | 17 | > __NOTE:__ This configuration will not work for you out of the box. You need 18 | to update the `GitRepository` sources to point to your own GitHub and GitLab 19 | repositories! 20 | 21 | ## Prerequisites 22 | 23 | - Kubernetes cluster 1.24+ (Docker Desktop) 24 | - Terraform v1.1+ 25 | - Vault v1.10+ 26 | - Flux v0.30+ 27 | - GitHub Personal Access Token 28 | - GitLab Personal Access Token 29 | 30 | ## Usage 31 | 32 | Set up secrets in your terminal. 33 | 34 | ```shell 35 | export GITHUB_TOKEN= 36 | export GITLAB_TOKEN= 37 | ``` 38 | 39 | Install ingress to the cluster. This will make it easier 40 | for you to access Vault from outside of the cluster. 41 | 42 | ```shell 43 | make ingress 44 | ``` 45 | 46 | Bootstrap Flux and apply the configuration. This will 47 | deploy Vault and all of the necessary components. 48 | 49 | ```shell 50 | make flux-bootstrap 51 | ``` 52 | 53 | ### Set up Vault and GitLab 54 | 55 | Initialize Vault. Copy the value from `unseal_keys_hex` in 56 | `unseal.json` to pass to the input command. 57 | 58 | ```shell 59 | make vault-init 60 | ``` 61 | 62 | Set up Vault credentials in shell. 63 | 64 | ```shell 65 | export VAULT_TOKEN=$(cat unseal.json | jq -r '.root_token') 66 | export VAULT_ADDR=http://localhost 67 | ``` 68 | 69 | Install secrets engines, including the database secrets engine. 70 | 71 | ```shell 72 | make vault-configure 73 | ``` 74 | 75 | Set up secret bootstrap to inject flux deploy token. 76 | 77 | ```shell 78 | make flux-token 79 | ``` 80 | 81 | ### Set up the Application 82 | 83 | Clone your GitLab project's repository, called `hashicups`. 84 | 85 | ```shell 86 | cd ~ 87 | git clone git@gitlab.com:/hashicups.git 88 | ``` 89 | 90 | Copy the `application/` folder in this working directory 91 | to the `hashicups` GitLab repository. 92 | 93 | ```shell 94 | cp application/ ~//hashicups/ 95 | ``` 96 | 97 | Push the changes to GitLab. 98 | 99 | ```shell 100 | git add . 101 | git commit -m "Initial commit" 102 | git push 103 | ``` 104 | 105 | Install applications. 106 | 107 | ```shell 108 | make applications 109 | ``` 110 | 111 | ## Clean up 112 | 113 | ```shell 114 | make clean 115 | ``` -------------------------------------------------------------------------------- /application/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | resources: 4 | - service-account.yaml 5 | - secrets.yaml 6 | - products-api.yaml -------------------------------------------------------------------------------- /application/products-api.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: product-api 6 | spec: 7 | selector: 8 | app: product-api 9 | ports: 10 | - name: http 11 | protocol: TCP 12 | port: 9090 13 | targetPort: 9090 14 | --- 15 | apiVersion: apps/v1 16 | kind: Deployment 17 | metadata: 18 | name: product-api 19 | labels: 20 | app: product-api 21 | spec: 22 | replicas: 1 23 | selector: 24 | matchLabels: 25 | app: product-api 26 | template: 27 | metadata: 28 | labels: 29 | app: product-api 30 | spec: 31 | serviceAccountName: product-api 32 | containers: 33 | - name: product-api 34 | image: hashicorpdemoapp/product-api:v0.0.22 35 | ports: 36 | - containerPort: 9090 37 | - containerPort: 9103 38 | env: 39 | - name: BIND_ADDRESS 40 | value: 0.0.0.0:9090 41 | command: ["/bin/sh"] 42 | args: ["-c", "export DB_CONNECTION=\"host=postgres port=5432 user=$(cat /mnt/secrets-store/db-username) password=$(cat /mnt/secrets-store/db-password) dbname=products sslmode=disable\" && /app/product-api"] 43 | volumeMounts: 44 | - name: 'vault-db-creds' 45 | mountPath: '/mnt/secrets-store' 46 | readOnly: true 47 | livenessProbe: 48 | httpGet: 49 | path: /health 50 | port: 9090 51 | initialDelaySeconds: 15 52 | timeoutSeconds: 1 53 | periodSeconds: 10 54 | failureThreshold: 30 55 | volumes: 56 | - name: vault-db-creds 57 | csi: 58 | driver: 'secrets-store.csi.k8s.io' 59 | readOnly: true 60 | volumeAttributes: 61 | secretProviderClass: 'products-db' -------------------------------------------------------------------------------- /application/secrets.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: secrets-store.csi.x-k8s.io/v1 3 | kind: SecretProviderClass 4 | metadata: 5 | name: products-db 6 | spec: 7 | provider: vault 8 | parameters: 9 | roleName: 'product' 10 | vaultAddress: 'http://vault:8200' 11 | objects: | 12 | - objectName: "db-username" 13 | secretPath: "hashicups/database/creds/product" 14 | secretKey: "username" 15 | - objectName: "db-password" 16 | secretPath: "hashicups/database/creds/product" 17 | secretKey: "password" -------------------------------------------------------------------------------- /application/service-account.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: ServiceAccount 4 | metadata: 5 | name: product-api 6 | automountServiceAccountToken: true -------------------------------------------------------------------------------- /clusters/local/application-bootstrap-source.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: source.toolkit.fluxcd.io/v1beta1 3 | kind: GitRepository 4 | metadata: 5 | name: application-bootstrap 6 | namespace: flux-system 7 | spec: 8 | interval: 10m0s 9 | ref: 10 | branch: main 11 | url: https://github.com/joatmon08/hashicorp-vault-flux.git -------------------------------------------------------------------------------- /clusters/local/csi-helm.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: helm.toolkit.fluxcd.io/v2beta1 3 | kind: HelmRelease 4 | metadata: 5 | name: csi 6 | namespace: default 7 | spec: 8 | chart: 9 | spec: 10 | chart: secrets-store-csi-driver 11 | sourceRef: 12 | kind: HelmRepository 13 | name: secrets-store-csi-driver 14 | interval: 10m0s 15 | values: 16 | enableSecretRotation: true 17 | syncSecret: 18 | enabled: true 19 | 20 | -------------------------------------------------------------------------------- /clusters/local/csi-source.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: source.toolkit.fluxcd.io/v1beta1 3 | kind: HelmRepository 4 | metadata: 5 | name: secrets-store-csi-driver 6 | namespace: default 7 | spec: 8 | interval: 10m0s 9 | url: https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts 10 | 11 | -------------------------------------------------------------------------------- /clusters/local/database-kustomization.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 3 | kind: Kustomization 4 | metadata: 5 | name: database 6 | namespace: flux-system 7 | spec: 8 | interval: 10m0s 9 | path: ./database 10 | prune: true 11 | sourceRef: 12 | kind: GitRepository 13 | name: application-bootstrap 14 | targetNamespace: default -------------------------------------------------------------------------------- /clusters/local/flux-system/gotk-sync.yaml: -------------------------------------------------------------------------------- 1 | # This manifest was generated by flux. DO NOT EDIT. 2 | --- 3 | apiVersion: source.toolkit.fluxcd.io/v1beta2 4 | kind: GitRepository 5 | metadata: 6 | name: flux-system 7 | namespace: flux-system 8 | spec: 9 | interval: 10m0s 10 | ref: 11 | branch: main 12 | secretRef: 13 | name: flux-system 14 | url: ssh://git@github.com/joatmon08/hashicorp-vault-flux 15 | --- 16 | apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 17 | kind: Kustomization 18 | metadata: 19 | name: flux-system 20 | namespace: flux-system 21 | spec: 22 | interval: 10m0s 23 | path: ./clusters/local 24 | prune: true 25 | sourceRef: 26 | kind: GitRepository 27 | name: flux-system 28 | -------------------------------------------------------------------------------- /clusters/local/flux-system/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | resources: 4 | - gotk-components.yaml 5 | - gotk-sync.yaml 6 | -------------------------------------------------------------------------------- /clusters/local/hashicorp-source.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: source.toolkit.fluxcd.io/v1beta1 3 | kind: HelmRepository 4 | metadata: 5 | name: hashicorp 6 | namespace: default 7 | spec: 8 | interval: 10m0s 9 | url: https://helm.releases.hashicorp.com 10 | 11 | -------------------------------------------------------------------------------- /clusters/local/hashicups-kustomization.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 3 | kind: Kustomization 4 | metadata: 5 | name: hashicups 6 | namespace: flux-system 7 | spec: 8 | interval: 10m0s 9 | path: ./application 10 | prune: true 11 | sourceRef: 12 | kind: GitRepository 13 | name: hashicups 14 | targetNamespace: default -------------------------------------------------------------------------------- /clusters/local/hashicups-source.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: source.toolkit.fluxcd.io/v1beta1 3 | kind: GitRepository 4 | metadata: 5 | name: hashicups 6 | namespace: flux-system 7 | spec: 8 | interval: 10m0s 9 | ref: 10 | branch: main 11 | url: https://gitlab.com/joatmon08/hashicups.git 12 | secretRef: 13 | name: gitlab-credentials -------------------------------------------------------------------------------- /clusters/local/repository-kustomization.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 3 | kind: Kustomization 4 | metadata: 5 | name: repository 6 | namespace: flux-system 7 | spec: 8 | interval: 10m0s 9 | path: ./gitlab 10 | prune: true 11 | sourceRef: 12 | kind: GitRepository 13 | name: application-bootstrap 14 | targetNamespace: flux-system -------------------------------------------------------------------------------- /clusters/local/vault-helm.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: helm.toolkit.fluxcd.io/v2beta1 3 | kind: HelmRelease 4 | metadata: 5 | name: vault 6 | namespace: default 7 | spec: 8 | chart: 9 | spec: 10 | chart: vault 11 | sourceRef: 12 | kind: HelmRepository 13 | name: hashicorp 14 | interval: 10m0s 15 | values: 16 | csi: 17 | enabled: true 18 | server: 19 | ha: 20 | enabled: true 21 | raft: 22 | config: | 23 | ui = true 24 | listener "tcp" { 25 | tls_disable = 1 26 | address = "[::]:8200" 27 | cluster_address = "[::]:8201" 28 | } 29 | storage "raft" { 30 | path = "/vault/data" 31 | } 32 | service_registration "kubernetes" {} 33 | enabled: true 34 | replicas: 1 35 | ingress: 36 | enabled: true 37 | hosts: 38 | - host: localhost 39 | ingressClassName: nginx 40 | 41 | -------------------------------------------------------------------------------- /clusters/local/vault-kustomization.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: kustomize.toolkit.fluxcd.io/v1beta2 3 | kind: Kustomization 4 | metadata: 5 | name: vault 6 | namespace: flux-system 7 | spec: 8 | interval: 10m0s 9 | path: ./vault/kubernetes 10 | prune: true 11 | sourceRef: 12 | kind: GitRepository 13 | name: application-bootstrap 14 | targetNamespace: default -------------------------------------------------------------------------------- /database/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | resources: 4 | - products-db.yaml -------------------------------------------------------------------------------- /database/products-db.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: postgres 6 | labels: 7 | app: postgres 8 | spec: 9 | type: ClusterIP 10 | ports: 11 | - port: 5432 12 | targetPort: 5432 13 | selector: 14 | app: postgres 15 | --- 16 | apiVersion: apps/v1 17 | kind: Deployment 18 | metadata: 19 | name: postgres 20 | spec: 21 | replicas: 1 22 | selector: 23 | matchLabels: 24 | service: postgres 25 | app: postgres 26 | template: 27 | metadata: 28 | labels: 29 | service: postgres 30 | app: postgres 31 | spec: 32 | containers: 33 | - name: postgres 34 | image: hashicorpdemoapp/product-api-db:v0.0.22 35 | imagePullPolicy: Always 36 | ports: 37 | - containerPort: 5432 38 | env: 39 | - name: POSTGRES_DB 40 | value: products 41 | - name: POSTGRES_USER 42 | value: postgres 43 | - name: POSTGRES_PASSWORD 44 | value: password 45 | volumeMounts: 46 | - mountPath: "/var/lib/postgresql/data" 47 | name: "pgdata" 48 | volumes: 49 | - name: pgdata 50 | emptyDir: {} -------------------------------------------------------------------------------- /gitlab/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | resources: 4 | - secrets.yaml -------------------------------------------------------------------------------- /gitlab/secrets.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: secrets-store.csi.x-k8s.io/v1 3 | kind: SecretProviderClass 4 | metadata: 5 | name: gitlab-credentials 6 | spec: 7 | provider: vault 8 | secretObjects: 9 | - secretName: gitlab-credentials 10 | type: Opaque 11 | data: 12 | - objectName: gitlab-username 13 | key: username 14 | - objectName: gitlab-password 15 | key: password 16 | parameters: 17 | roleName: 'flux' 18 | vaultAddress: 'http://vault:8200' 19 | objects: | 20 | - objectName: "gitlab-username" 21 | secretPath: "hashicups/flux/data/gitlab" 22 | secretKey: "username" 23 | - objectName: "gitlab-password" 24 | secretPath: "hashicups/flux/data/gitlab" 25 | secretKey: "password" 26 | --- 27 | apiVersion: apps/v1 28 | kind: Deployment 29 | metadata: 30 | name: secrets-store-inline 31 | labels: 32 | app: secrets-store-inline 33 | spec: 34 | replicas: 1 35 | selector: 36 | matchLabels: 37 | app: secrets-store-inline 38 | template: 39 | metadata: 40 | labels: 41 | app: secrets-store-inline 42 | spec: 43 | serviceAccountName: source-controller 44 | containers: 45 | - name: busybox 46 | image: k8s.gcr.io/e2e-test-images/busybox:1.29 47 | command: 48 | - "/bin/sleep" 49 | - "10000" 50 | volumeMounts: 51 | - name: secrets-store 52 | mountPath: "/mnt/secrets-store" 53 | readOnly: true 54 | volumes: 55 | - name: secrets-store 56 | csi: 57 | driver: secrets-store.csi.k8s.io 58 | readOnly: true 59 | volumeAttributes: 60 | secretProviderClass: "gitlab-credentials" -------------------------------------------------------------------------------- /set.sh: -------------------------------------------------------------------------------- 1 | export VAULT_TOKEN=$(cat unseal.json | jq -r '.root_token') 2 | export VAULT_ADDR=http://localhost -------------------------------------------------------------------------------- /vault/kubernetes/flux-sa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | type: kubernetes.io/service-account-token 4 | metadata: 5 | name: source-controller 6 | namespace: flux-system 7 | annotations: 8 | kubernetes.io/service-account.name: "source-controller" 9 | kubernetes.io/service-account.namespace: "flux-system" -------------------------------------------------------------------------------- /vault/kubernetes/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | resources: 4 | - vault-sa.yaml 5 | - flux-sa.yaml 6 | - product-sa.yaml -------------------------------------------------------------------------------- /vault/kubernetes/product-sa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | type: kubernetes.io/service-account-token 4 | metadata: 5 | name: product-api 6 | namespace: default 7 | annotations: 8 | kubernetes.io/service-account.name: "product-api" -------------------------------------------------------------------------------- /vault/kubernetes/vault-sa.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Secret 3 | type: kubernetes.io/service-account-token 4 | metadata: 5 | name: vault 6 | annotations: 7 | kubernetes.io/service-account.name: "vault" -------------------------------------------------------------------------------- /vault/terraform/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/gitlabhq/gitlab" { 5 | version = "3.12.0" 6 | constraints = "~> 3.12" 7 | hashes = [ 8 | "h1:DXO6Kwy9QpnFzJQ6NdkjZu4PnDHSYHMbvDxLlfEl0ho=", 9 | "zh:1c3e89cf19118fc07d7b04257251fc9897e722c16e0a0df7b07fcd261f8c12e7", 10 | "zh:207f7ffaaf16f3d0db9eec847867871f4a9eb9bb9109d9ab9c9baffade1a4688", 11 | "zh:2360bdd3253a15fbbb6581759aa9499235de670d13f02272cbe408cb425dc625", 12 | "zh:2a9bec466163baeb70474fab7b43aababdf28b240f2f4917299dfe1a952fd983", 13 | "zh:3a6ea735b5324c17aa6776bff3b2c1c2aeb2b6c20b9c944075c8244367eb7e4c", 14 | "zh:3aa73c622187c06c417e1cd98cd83f9a2982c478e4f9f6cd76fbfaec3f6b36e8", 15 | "zh:51ace107c8ba3f2bb7f7d246db6a0428ef94aafceca38df5908167f336963ec8", 16 | "zh:53a35a827596178c2a12cf33d1f0d0b4cf38cd32d2cdfe2443bdd6ebb06561be", 17 | "zh:5bece68a724bffd2e66293429319601d81ac3186bf93337c797511672f80efd0", 18 | "zh:60f21e8737be59933a923c085dcb7674fcd44d8a5f2e4738edc70ae726666204", 19 | "zh:9fb277f13dd8f81dee7f93230e7d1593aca49c4788360c3f2d4e42b8f6bb1a8f", 20 | "zh:ac63a9b4a3a50a3164ee26f1e64cc6878fcdb414f50106abe3dbeb7532edc8cd", 21 | "zh:ed083de9fce2753e3dfeaa1356508ecb0f218fbace8a8ef7b56f3f324fff593b", 22 | "zh:ed966026c76a334b6bd6d621c06c5db4a6409468e4dd99d9ad099d3a9de22768", 23 | ] 24 | } 25 | 26 | provider "registry.terraform.io/hashicorp/kubernetes" { 27 | version = "2.8.0" 28 | constraints = ">= 2.4.1" 29 | hashes = [ 30 | "h1:tfU8BStZIt2d6KIGTRNjWb09zeVzh3UFGNRGVgFce+A=", 31 | "zh:0cf42c17c05ae5f0f5eb4b2c375dd2068960b97392e50823e47b2cee7b5e01be", 32 | "zh:29e3751eceae92c7400a17fe3a5394ed761627bcadfda66e7ac91d6485c37927", 33 | "zh:2d95584504c651e1e2e49fbb5fae1736e32a505102c3dbd2c319b26884a7d3d5", 34 | "zh:4a5f1d915c19e7c7b4f04d7d68f82db2c872dad75b9e6f33a6ddce43aa160405", 35 | "zh:4b959187fd2c884a4c6606e1c4edc7b506ec4cadb2742831f37aca1463eb349d", 36 | "zh:5e76a2b81c93d9904d50c2a703845f79d2b080c2f87c07ef8f168592033d638f", 37 | "zh:c5aa21a7168f96afa4b4776cbd7eefd3e1f47d48430dce75c7f761f2d2fac77b", 38 | "zh:d45e8bd98fc6752ea087e744efdafb209e7ec5a4224f9affee0a24fb51d26bb9", 39 | "zh:d4739255076ed7f3ac2a06aef89e8e48a87667f3e470c514ce2185c0569cc1fb", 40 | "zh:dbd2f11529a422ffd17040a70c0cc2802b7f1be2499e976dc22f1138d022b1b4", 41 | "zh:dbd5357082b2485bb9978bce5b6d508d6b431d15c53bfa1fcc2781131826b5d8", 42 | ] 43 | } 44 | 45 | provider "registry.terraform.io/hashicorp/vault" { 46 | version = "2.24.1" 47 | constraints = "~> 2.22" 48 | hashes = [ 49 | "h1:BYE99Z9O73t1aF38BQ5eOvBR9Rjdw6+UOkst+s7cj5k=", 50 | "zh:1968be03bbc83c9f512a60f0a018cb0cf4c9a4a0f9e606f9a7436ae06108200f", 51 | "zh:23ef25b530dcf2f60692e261d2a56c112138d79a739f2c720bee818cf040a20f", 52 | "zh:2b80879cf8110254eeeb55b36ce542e9cdaefc047d450368ff0ca631b29d41d6", 53 | "zh:3d803047407a4e7ccb51cd88b38648e50517e70b97842ae1262b5c5a92eb8ede", 54 | "zh:7edfd0323a839903e7fc5f45acce8dd61c43b356c09016e1bd43d6880bd82be6", 55 | "zh:7efa2c6d1d0bac9478adb27fc68035ca9dc2107dae55d921a760a8ad237eb691", 56 | "zh:a1f9d34e2ac8b3a3d177faef4f11690068919ef7d73256def6685cfd9282f83d", 57 | "zh:a6c34746e0085ae49e3845fc58597d2d5778fcb2136fedb413b3e30ba77dd2bd", 58 | "zh:a73eb4bc061b5babd7ea4d5f3f85f4b4c6d379982098411a29a7d7459fc37ab2", 59 | "zh:aadecf464ead4ae30821495d8181e842c18a2537c018245509a96532eeaf7678", 60 | "zh:e3ae8c48804065fa4f85095002f945adbd5cd3966c0b1afced7d839007586105", 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /vault/terraform/auth.tf: -------------------------------------------------------------------------------- 1 | # data "kubernetes_service_account" "vault_auth" { 2 | # metadata { 3 | # name = "vault" 4 | # } 5 | # } 6 | 7 | data "kubernetes_secret" "vault_auth" { 8 | metadata { 9 | name = "vault" 10 | } 11 | } 12 | 13 | resource "vault_auth_backend" "kubernetes" { 14 | type = "kubernetes" 15 | } 16 | 17 | resource "vault_kubernetes_auth_backend_config" "kubernetes" { 18 | backend = vault_auth_backend.kubernetes.path 19 | kubernetes_host = "https://kubernetes.docker.internal:6443" 20 | kubernetes_ca_cert = data.kubernetes_secret.vault_auth.data["ca.crt"] 21 | token_reviewer_jwt = data.kubernetes_secret.vault_auth.data.token 22 | issuer = "https://kubernetes.default.svc.cluster.local" 23 | } -------------------------------------------------------------------------------- /vault/terraform/database.tf: -------------------------------------------------------------------------------- 1 | resource "vault_mount" "postgres" { 2 | path = "${var.application}/database" 3 | type = "database" 4 | } 5 | 6 | resource "vault_database_secret_backend_connection" "postgres" { 7 | backend = vault_mount.postgres.path 8 | name = var.service 9 | allowed_roles = [var.service] 10 | postgresql { 11 | connection_url = "postgresql://{{username}}:{{password}}@${local.database_host}:${local.database_port}/${local.database_name}?sslmode=disable" 12 | } 13 | 14 | data = { 15 | username = local.database_username 16 | password = local.database_password 17 | } 18 | } 19 | 20 | resource "vault_database_secret_backend_role" "postgres" { 21 | backend = vault_mount.postgres.path 22 | name = var.service 23 | db_name = vault_database_secret_backend_connection.postgres.name 24 | creation_statements = ["CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";"] 25 | revocation_statements = ["ALTER ROLE \"{{name}}\" NOLOGIN;"] 26 | default_ttl = 3600 27 | max_ttl = 3600 28 | } 29 | 30 | locals { 31 | database_creds_path = "${vault_mount.postgres.path}/creds/${var.service}" 32 | } 33 | 34 | data "vault_policy_document" "product" { 35 | rule { 36 | path = local.database_creds_path 37 | capabilities = ["read"] 38 | description = "read all ${var.service}" 39 | } 40 | } 41 | 42 | resource "vault_policy" "product" { 43 | name = var.service 44 | policy = data.vault_policy_document.product.hcl 45 | } 46 | 47 | resource "vault_kubernetes_auth_backend_role" "product" { 48 | backend = vault_auth_backend.kubernetes.path 49 | role_name = var.service 50 | bound_service_account_names = [var.service_account] 51 | bound_service_account_namespaces = [var.namespace] 52 | token_ttl = 3600 53 | token_policies = [vault_policy.product.name] 54 | } -------------------------------------------------------------------------------- /vault/terraform/gitlab.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | flux_username = "flux" 3 | } 4 | 5 | resource "gitlab_project" "hashicups" { 6 | name = "hashicups" 7 | description = "Codebase for HashiCups" 8 | 9 | visibility_level = "private" 10 | } 11 | 12 | resource "gitlab_deploy_token" "hashicups" { 13 | depends_on = [gitlab_project.hashicups] 14 | project = gitlab_project.hashicups.id 15 | name = "Deploy Token for Flux" 16 | username = local.flux_username 17 | 18 | scopes = ["read_repository", "read_registry"] 19 | } 20 | 21 | resource "vault_mount" "flux" { 22 | path = "${var.application}/flux" 23 | type = "kv-v2" 24 | description = "For ${var.application} Flux deploy secrets" 25 | } 26 | 27 | resource "vault_generic_secret" "gitlab" { 28 | path = "${vault_mount.flux.path}/gitlab" 29 | 30 | data_json = jsonencode({ 31 | username = "${gitlab_deploy_token.hashicups.username}" 32 | password = "${gitlab_deploy_token.hashicups.token}" 33 | }) 34 | } 35 | 36 | locals { 37 | gitlab_creds_path = "${vault_mount.flux.path}/data/gitlab" 38 | flux_source_controller_service_account = "source-controller" 39 | flux_namespace = "flux-system" 40 | } 41 | 42 | data "vault_policy_document" "gitlab" { 43 | rule { 44 | path = local.gitlab_creds_path 45 | 46 | capabilities = [ 47 | "read" 48 | ] 49 | 50 | description = "read GitLab credentials" 51 | } 52 | } 53 | 54 | resource "vault_policy" "gitlab" { 55 | name = "gitlab" 56 | policy = data.vault_policy_document.gitlab.hcl 57 | } 58 | 59 | resource "vault_kubernetes_auth_backend_role" "gitlab" { 60 | backend = vault_auth_backend.kubernetes.path 61 | role_name = "flux" 62 | bound_service_account_names = [local.flux_source_controller_service_account] 63 | bound_service_account_namespaces = [local.flux_namespace] 64 | token_ttl = 3600 65 | token_policies = [vault_policy.gitlab.name] 66 | } -------------------------------------------------------------------------------- /vault/terraform/outputs.tf: -------------------------------------------------------------------------------- 1 | output "database_creds_path" { 2 | value = local.database_creds_path 3 | } 4 | 5 | output "flux_creds_path" { 6 | value = local.gitlab_creds_path 7 | } -------------------------------------------------------------------------------- /vault/terraform/providers.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.0" 3 | required_providers { 4 | vault = { 5 | source = "hashicorp/vault" 6 | version = "~> 2.22" 7 | } 8 | kubernetes = { 9 | source = "hashicorp/kubernetes" 10 | version = "~> 2.4" 11 | } 12 | gitlab = { 13 | source = "gitlabhq/gitlab" 14 | version = "~> 3.12" 15 | } 16 | } 17 | } 18 | 19 | provider "vault" {} 20 | 21 | provider "kubernetes" { 22 | config_path = "~/.kube/config" 23 | config_context = "docker-desktop" 24 | } 25 | 26 | provider "gitlab" {} -------------------------------------------------------------------------------- /vault/terraform/variables.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | database_username = "postgres" 3 | database_password = "password" 4 | database_host = "postgres" 5 | database_name = "products" 6 | database_port = 5432 7 | } 8 | 9 | variable "application" { 10 | type = string 11 | description = "Name of application for base path" 12 | default = "hashicups" 13 | } 14 | 15 | variable "service" { 16 | type = string 17 | description = "Name of Kubernetes service for Vault role" 18 | default = "product" 19 | } 20 | 21 | variable "service_account" { 22 | type = string 23 | description = "Name of Kubernetes service account used for service" 24 | default = "product-api" 25 | } 26 | 27 | variable "namespace" { 28 | type = string 29 | description = "Name of Kubernetes namespace used for service" 30 | default = "default" 31 | } -------------------------------------------------------------------------------- /vault/values.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | ingress: 3 | enabled: true 4 | hosts: 5 | - host: localhost 6 | ingressClassName: nginx 7 | ha: 8 | enabled: true 9 | replicas: 1 10 | raft: 11 | enabled: true 12 | config: | 13 | ui = true 14 | listener "tcp" { 15 | tls_disable = 1 16 | address = "[::]:8200" 17 | cluster_address = "[::]:8201" 18 | } 19 | storage "raft" { 20 | path = "/vault/data" 21 | } 22 | service_registration "kubernetes" {} 23 | 24 | csi: 25 | enabled: true --------------------------------------------------------------------------------