├── .gitignore
├── LICENSE
├── README.md
├── application
├── README.md
├── akka
│ ├── README.md
│ ├── java
│ │ ├── Dockerfile
│ │ └── example
│ │ │ ├── build.gradle
│ │ │ ├── build.sbt
│ │ │ ├── pom.xml
│ │ │ ├── project
│ │ │ ├── build.properties
│ │ │ └── plugins.sbt
│ │ │ └── src
│ │ │ ├── main
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── example
│ │ │ │ │ └── Example.java
│ │ │ └── resources
│ │ │ │ ├── application.conf
│ │ │ │ └── logback.xml
│ │ │ └── test
│ │ │ └── resources
│ │ │ └── application-test.conf
│ └── scala
│ │ ├── Dockerfile
│ │ └── example
│ │ ├── .gitignore
│ │ ├── build.sbt
│ │ ├── project
│ │ ├── build.properties
│ │ └── plugins.sbt
│ │ └── src
│ │ ├── main
│ │ ├── resources
│ │ │ ├── application.conf
│ │ │ └── logback.xml
│ │ └── scala
│ │ │ └── com
│ │ │ └── example
│ │ │ └── Example.scala
│ │ └── test
│ │ └── resources
│ │ └── application-test.conf
├── aspnet
│ ├── cli-example
│ │ ├── Dockerfile
│ │ ├── README.md
│ │ ├── aspnetapp.sln
│ │ └── example
│ │ │ ├── Pages
│ │ │ ├── Index.cshtml
│ │ │ ├── Index.cshtml.cs
│ │ │ └── _ViewImports.cshtml
│ │ │ ├── Program.cs
│ │ │ ├── Properties
│ │ │ └── launchSettings.json
│ │ │ ├── Startup.cs
│ │ │ ├── appsettings.Development.json
│ │ │ ├── appsettings.json
│ │ │ └── example.csproj
│ └── sdk-example
│ │ ├── Dockerfile
│ │ ├── README.md
│ │ └── example
│ │ ├── Pages
│ │ ├── Index.cshtml
│ │ └── Index.cshtml.cs
│ │ └── example.csproj
├── django
│ ├── Dockerfile
│ ├── README.md
│ ├── requirements.txt
│ ├── urls.py
│ └── views.py
├── flask
│ ├── Dockerfile
│ ├── README.md
│ ├── app.py
│ └── requirements.txt
├── kitura
│ ├── Dockerfile
│ ├── HelloKitura
│ │ ├── Package.swift
│ │ └── Sources
│ │ │ └── HelloKitura
│ │ │ └── main.swift
│ └── README.md
├── nodejs
│ ├── Dockerfile
│ ├── README.md
│ ├── index.js
│ ├── package-lock.json
│ └── package.json
├── perfect
│ ├── Dockerfile
│ ├── PerfectTemplate
│ │ └── Sources
│ │ │ └── PerfectTemplate
│ │ │ └── main.swift
│ └── README.md
├── phoenix
│ ├── Dockerfile
│ ├── README.md
│ └── example
│ │ ├── controllers
│ │ └── example_controller.ex
│ │ └── router.ex
├── play
│ ├── README.md
│ ├── java
│ │ ├── Dockerfile
│ │ └── example
│ │ │ ├── .gitignore
│ │ │ ├── app
│ │ │ └── controllers
│ │ │ │ └── HomeController.java
│ │ │ ├── build.sbt
│ │ │ ├── conf
│ │ │ ├── application.conf
│ │ │ ├── logback.xml
│ │ │ └── routes
│ │ │ ├── project
│ │ │ ├── build.properties
│ │ │ └── plugins.sbt
│ │ │ └── test
│ │ │ └── controllers
│ │ │ └── HomeControllerTest.java
│ └── scala
│ │ ├── Dockerfile
│ │ └── example
│ │ ├── .gitignore
│ │ ├── app
│ │ └── controllers
│ │ │ └── HomeController.scala
│ │ ├── build.sbt
│ │ ├── conf
│ │ ├── application.conf
│ │ ├── logback.xml
│ │ ├── messages
│ │ └── routes
│ │ ├── project
│ │ ├── build.properties
│ │ └── plugins.sbt
│ │ └── test
│ │ └── controllers
│ │ └── HomeControllerSpec.scala
├── rails
│ ├── Dockerfile
│ ├── README.md
│ ├── application_controller.rb
│ └── routes.rb
├── ruby
│ ├── Dockerfile
│ ├── Gemfile
│ ├── README.md
│ └── myapp.rb
└── spring-boot
│ ├── Dockerfile
│ ├── README.md
│ ├── pom.xml
│ └── src
│ └── main
│ └── java
│ └── example
│ └── ExampleApplication.java
├── aws
├── ec2
│ ├── README.md
│ ├── app.tf
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── ecs
│ ├── README.md
│ ├── app.tf
│ ├── cluster.tf
│ ├── main.tf
│ └── variables.tf
└── eks
│ ├── README.md
│ ├── app.tf
│ ├── cluster.tf
│ ├── main.tf
│ └── variables.tf
├── ci
├── circleci
│ ├── README.md
│ └── publish-docker
│ │ ├── .circleci
│ │ └── config.yml
│ │ └── Dockerfile
├── github-actions
│ └── publish-docker
│ │ ├── .github
│ │ └── workflows
│ │ │ └── main.yml
│ │ └── Dockerfile
└── gitlab-ci
│ ├── README.md
│ ├── deploy-aws
│ ├── .gitlab-ci.yml
│ ├── deploy.json
│ └── deploy.sh
│ └── publish-docker
│ ├── .gitlab-ci.yml
│ └── Dockerfile
├── devops-tools
└── terraform
│ ├── README.md
│ ├── main.tf
│ ├── output.tf
│ └── variables.tf
└── google-cloud
├── gce
├── README.md
├── app.tf
├── main.tf
├── outputs.tf
└── variables.tf
└── gke
├── README.md
├── app.tf
├── main.tf
└── variables.tf
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | **/.terraform
3 | **/*.tfstate
4 | **/*.tfstate.backup
5 | **/terraform.tfvars
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | SecretHub has joined 1Password! Find out more on the SecretHub blog. 🎉
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Examples
12 |
13 |
14 | [](https://discord.gg/NWmxVeb)
15 |
16 | > [SecretHub][secrethub] is a secrets management tool that works for every engineer. Securely provision passwords and keys throughout your entire stack with just a few lines of code.
17 |
18 | This repository contains code examples for integrations with SecretHub. The README.md for these examples can be found in every directory. For all integrations, take a look at the [integrations page](https://secrethub.io/docs/#integrations).
19 |
20 | We're adding more examples over time (starting with the ones listed below), so keep a lookout for new examples. We'll be adding the ones listed here first.
21 |
22 | If you have a great example of a SecretHub integration yourself or a way to improve an example, feel free (and very welcome) to make a pull request.
23 |
24 | ## Examples
25 |
26 | * CI/CD
27 | * [CircleCI](ci/circleci/)
28 | * [GitHub Actions](ci/github-actions/publish-docker/.github/workflows/main.yml)
29 | * Travis CI
30 | * [GitLab CI](ci/gitlab-ci/)
31 | * Jenkins
32 | * Cloud
33 | * [AWS EC2](aws/ec2)
34 | * [AWS ECS](aws/ecs/)
35 | * AWS Lambda (Golang)
36 | * [Google Compute Engine](google-cloud/gce)
37 | * [Google Kubernetes Engine](google-cloud/gke)
38 | * Linux VMS
39 | * Application
40 | * [Flask](application/flask)
41 | * [Django](application/django)
42 | * [Node.js](application/nodejs)
43 | * [Ruby](application/ruby)
44 | * [Rails](application/rails)
45 | * [Spring Boot](application/spring-boot)
46 | * [ASP.NET](application/aspnet)
47 | * [Kitura](application/kitura)
48 | * [Perfect](application/perfect)
49 | * DevOps tools
50 | * [Terraform](devops-tools/terraform)
51 | * Ansible
52 | * Chef
53 | * Puppet
54 | * IDE
55 | * VS Code
56 |
57 | [secrethub]: https://secrethub.io/
58 |
--------------------------------------------------------------------------------
/application/README.md:
--------------------------------------------------------------------------------
1 | # Example applications
2 | This folder contains the examples for the web application frameworks. The basic structure of all the examples is as followed:
3 | 1. Init the SecretHub demo repository
4 | 2. Create a service account on the demo repository
5 | 3. Build the docker file
6 | 4. Run the docker file
7 | 5. Check if the example works with a curl on localhost:8080. The example returns code 200 if successful and 500 otherwise
8 | ```
9 | curl -i localhost:8080
10 | ```
11 |
--------------------------------------------------------------------------------
/application/akka/README.md:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 | This ASP.NET example checks if the environment variables `DEMO_USERNAME` and `DEMO_PASSWORD` have been set. If that's the case, you'll receive a `200` on http://localhost:8080 and if it's not, you'll get a `500`.
7 |
8 | ## Prerequisites
9 | 1. [Docker](https://docs.docker.com/install/) installed and running
10 | 1. [SecretHub](https://secrethub.io/docs/start/getting-started/#install) installed
11 | 1. A SecretHub repo that contains a `username` and `password` secret. To create it, run `secrethub demo init`.
12 |
13 | ## Running the example
14 |
15 | Set the SecretHub username in an environment variable
16 | ```
17 | export SECRETHUB_USERNAME=
18 | ```
19 |
20 | Create a service account for the demo repo
21 | ```
22 | secrethub service init --description demo_service \
23 | --permission read --file demo_service.cred ${SECRETHUB_USERNAME}/demo
24 | ```
25 |
26 | Build the ASP.NET docker demo
27 | ```
28 | docker build . -t aspnet-secrethub-demo
29 | ```
30 |
31 | Run the docker demo with the secrets in the environment variables
32 | ```
33 | docker run -p 8080:80 \
34 | -e DEMO_USERNAME=secrethub://${SECRETHUB_USERNAME}/demo/username \
35 | -e DEMO_PASSWORD=secrethub://${SECRETHUB_USERNAME}/demo/password \
36 | -e SECRETHUB_CREDENTIAL=$(cat demo_service.cred) \
37 | aspnet-secrethub-demo
38 | ```
39 |
40 | If you now visit http://localhost:8080, you should see the welcome message including your username.
41 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/aspnetapp.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 15
3 | VisualStudioVersion = 15.0.27130.2027
4 | MinimumVisualStudioVersion = 15.0.26124.0
5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "example", "example\example.csproj", "{5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}"
6 | EndProject
7 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1E1C7ABA-885A-4273-811E-B66AD28F9A87}"
8 | ProjectSection(SolutionItems) = preProject
9 | Directory.Build.props = Directory.Build.props
10 | Dockerfile = Dockerfile
11 | Dockerfile.alpine-x64 = Dockerfile.alpine-x64
12 | EndProjectSection
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Debug|x64 = Debug|x64
18 | Debug|x86 = Debug|x86
19 | Release|Any CPU = Release|Any CPU
20 | Release|x64 = Release|x64
21 | Release|x86 = Release|x86
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Debug|x64.ActiveCfg = Debug|Any CPU
27 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Debug|x64.Build.0 = Debug|Any CPU
28 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Debug|x86.ActiveCfg = Debug|Any CPU
29 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Debug|x86.Build.0 = Debug|Any CPU
30 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Release|x64.ActiveCfg = Release|Any CPU
33 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Release|x64.Build.0 = Release|Any CPU
34 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Release|x86.ActiveCfg = Release|Any CPU
35 | {5FDCC1ED-9F59-47ED-969D-5E463CDD8D52}.Release|x86.Build.0 = Release|Any CPU
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | GlobalSection(ExtensibilityGlobals) = postSolution
41 | SolutionGuid = {C9A7C5A2-5C90-4AD9-ABB8-6F2D2364D5AF}
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/Pages/Index.cshtml:
--------------------------------------------------------------------------------
1 | @page
2 | @model IndexModel
3 |
4 | @Model.Content()
5 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/Pages/Index.cshtml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 | using Microsoft.AspNetCore.Mvc.RazorPages;
3 | using Microsoft.Extensions.Logging;
4 | using System;
5 |
6 | namespace example.Pages
7 | {
8 | public class IndexModel : PageModel
9 | {
10 | public string Content()
11 | {
12 | string content;
13 | string username = Environment.GetEnvironmentVariable("DEMO_USERNAME");
14 | string password = Environment.GetEnvironmentVariable("DEMO_PASSWORD");
15 |
16 | if( (string.IsNullOrEmpty(username)) || (string.IsNullOrEmpty(username)) ){
17 | Response.StatusCode = 500;
18 | content = "not all variables are set";
19 | }
20 | else{
21 | Response.StatusCode = 200;
22 | content = "Welcome " + username;
23 | }
24 | return content;
25 | }
26 |
27 | public void OnGet()
28 | {
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/Pages/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using example
2 | @namespace example.Pages
3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace example
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | CreateHostBuilder(args).Build().Run();
17 | }
18 |
19 | public static IHostBuilder CreateHostBuilder(string[] args) =>
20 | Host.CreateDefaultBuilder(args)
21 | .ConfigureWebHostDefaults(webBuilder =>
22 | {
23 | webBuilder.UseStartup();
24 | });
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:53930",
7 | "sslPort": 44370
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "aspnetapp": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | },
26 | "publicdev": {
27 | "commandName": "Project",
28 | "launchBrowser": true,
29 | "applicationUrl": "http://+:80",
30 | "environmentVariables": {
31 | "ASPNETCORE_ENVIRONMENT": "Development"
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/Startup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.HttpsPolicy;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.DependencyInjection;
10 | using Microsoft.Extensions.Hosting;
11 |
12 | namespace example
13 | {
14 | public class Startup
15 | {
16 | public Startup(IConfiguration configuration)
17 | {
18 | Configuration = configuration;
19 | }
20 |
21 | public IConfiguration Configuration { get; }
22 |
23 | // This method gets called by the runtime. Use this method to add services to the container.
24 | public void ConfigureServices(IServiceCollection services)
25 | {
26 | services.AddRazorPages();
27 | }
28 |
29 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
30 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
31 | {
32 | if (env.IsDevelopment())
33 | {
34 | app.UseDeveloperExceptionPage();
35 | }
36 | else
37 | {
38 | app.UseExceptionHandler("/Error");
39 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
40 | app.UseHsts();
41 | }
42 |
43 | app.UseHttpsRedirection();
44 | app.UseStatusCodePages();
45 | app.UseStaticFiles();
46 |
47 | app.UseRouting();
48 |
49 | app.UseAuthorization();
50 |
51 | app.UseEndpoints(endpoints =>
52 | {
53 | endpoints.MapRazorPages();
54 | });
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Debug",
5 | "System": "Information",
6 | "Microsoft": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/application/aspnet/cli-example/example/example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/application/aspnet/sdk-example/Dockerfile:
--------------------------------------------------------------------------------
1 | # .NET CORE 3.1 base image
2 | FROM mcr.microsoft.com/dotnet/core/sdk:3.1
3 |
4 | # Create new app
5 | RUN dotnet new webApp -o example --no-https
6 |
7 | # Add modified files
8 | COPY ./example ./example
9 |
10 | # Change workdir so the run command will be run in project
11 | WORKDIR /example
12 |
13 | # Default port
14 | EXPOSE 5000
15 |
16 | # Run command, set to receive requests from everywhere (0.0.0.0) on default
17 | CMD ["dotnet", "run", "--urls", "http://0.0.0.0:5000"]
18 |
--------------------------------------------------------------------------------
/application/aspnet/sdk-example/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | This example demonstrates the use of the [.NET SDK](https://github.com/secrethub/secrethub-dotnet) in an ASP.NET application.
7 | Following the steps below will result in an welcome message on http://localhost:5000.
8 | If any error occurs, you will receive a descriptive error message in the console.
9 |
10 | ## Prerequisites
11 | 1. [Docker](https://docs.docker.com/install/) installed and running
12 | 1. [SecretHub](https://secrethub.io/docs/start/getting-started/#install) installed
13 | 1. A SecretHub repo that contains a `username` and `password` secret. To create it, run `secrethub demo init`.
14 |
15 | ## Running the example
16 |
17 | Set the SecretHub username in an environment variable.
18 | ```
19 | export SECRETHUB_USERNAME=
20 | ```
21 |
22 | Create a service account for the demo repo.
23 | ```
24 | secrethub service init --description demo_service \
25 | --permission read --file demo_service.cred ${SECRETHUB_USERNAME}/demo
26 | ```
27 |
28 | Build the ASP.NET docker demo.
29 | ```
30 | docker build . -t aspnet-secrethub-demo
31 | ```
32 |
33 | Run the docker demo, passing the newly created service credential and the paths in the secret store as environment variables.
34 | ```
35 | docker run -e SECRETHUB_CREDENTIAL=$(cat demo_service.cred) \
36 | -e DEMO_USERNAME=secrethub://${SECRETHUB_USERNAME}/demo/username \
37 | -e DEMO_PASSWORD=secrethub://${SECRETHUB_USERNAME}/demo/password \
38 | -p 5000:5000 aspnet-secrethub-demo
39 | ```
40 |
41 | If you now visit http://localhost:5000, you should see the welcome message including your username.
42 |
--------------------------------------------------------------------------------
/application/aspnet/sdk-example/example/Pages/Index.cshtml:
--------------------------------------------------------------------------------
1 | @page
2 | @model IndexModel
3 | @{
4 | ViewData["Title"] = "Home page";
5 | }
6 |
7 |
4 |
5 |
6 | This Phoenix example checks if the environment variables `DEMO_USERNAME` and `DEMO_PASSWORD` have been set. If that's the case, you'll receive a personalized greeting message on http://localhost:4000, otherwise you will get an error message.
7 |
8 | ## Prerequisites
9 | 1. [Docker](https://docs.docker.com/install/) installed and running
10 | 1. [SecretHub](https://secrethub.io/docs/start/getting-started/#install) installed
11 | 1. A SecretHub repo that contains a `username` and `password` secret. To create it, run `secrethub demo init`.
12 |
13 | ## Running the example
14 |
15 | Set the SecretHub username in an environment variable
16 | ```
17 | export SECRETHUB_USERNAME=
18 | ```
19 |
20 | Create a service account for the demo repo
21 | ```
22 | secrethub service init --description demo_service \
23 | --permission read --file demo_service.cred ${SECRETHUB_USERNAME}/demo
24 | ```
25 |
26 | Build the Phoenix docker demo
27 | ```
28 | docker build . -t phoenix-secrethub-demo
29 | ```
30 |
31 | Run the docker demo with the secrets in the environment variables
32 | ```
33 | docker run -p 4000:4000 \
34 | -e DEMO_USERNAME=secrethub://${SECRETHUB_USERNAME}/demo/username \
35 | -e DEMO_PASSWORD=secrethub://${SECRETHUB_USERNAME}/demo/password \
36 | -e SECRETHUB_CREDENTIAL=$(cat demo_service.cred) \
37 | phoenix-secrethub-demo
38 | ```
39 |
40 | If you now visit http://localhost:4000, you should see the welcome message including your username.
41 |
--------------------------------------------------------------------------------
/application/phoenix/example/controllers/example_controller.ex:
--------------------------------------------------------------------------------
1 | defmodule Example.ExampleController do
2 | use ExampleWeb, :controller
3 |
4 | def index(conn, _params) do
5 | text conn, response()
6 | end
7 |
8 | def response() do
9 | if System.get_env("DEMO_USERNAME") != nil && System.get_env("DEMO_PASSWORD") != nil do
10 | "Hello, " <> System.get_env("DEMO_USERNAME") <> "!"
11 | else
12 | "not all the variables have been set"
13 | end
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/application/phoenix/example/router.ex:
--------------------------------------------------------------------------------
1 | defmodule ExampleWeb.Router do
2 | use ExampleWeb, :router
3 |
4 | pipeline :api do
5 | plug :accepts, ["html"]
6 | end
7 |
8 | scope "/", Example do
9 | pipe_through :api # Use the default browser stack
10 |
11 | get "/", ExampleController, :index
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/application/play/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | This Play example checks if the environment variables `DEMO_USERNAME` and `DEMO_PASSWORD` have been set. If that's the case, you'll receive a `200` on http://localhost:9000 and if it's not, you'll get a `500`.
7 |
8 | ## Prerequisites
9 | 1. [Docker](https://docs.docker.com/install/) installed and running
10 | 1. [SecretHub](https://secrethub.io/docs/start/getting-started/#install) installed
11 | 1. A SecretHub repo that contains a `username` and `password` secret. To create it, run `secrethub demo init`.
12 |
13 | ## Running the example
14 |
15 | Set the SecretHub username in an environment variable
16 | ```
17 | export SECRETHUB_USERNAME=
18 | ```
19 |
20 | Create a service account for the demo repo
21 | ```
22 | secrethub service init --description demo_service \
23 | --permission read --file demo_service.cred ${SECRETHUB_USERNAME}/demo
24 | ```
25 |
26 | Build the play docker demo. You can choose `java` or `scala`, depending on which language you want to see the example in action.
27 | ```
28 | docker build {java | scala} -t play-secrethub-demo
29 | ```
30 |
31 | Run the docker demo with the secrets in the environment variables
32 | ```
33 | docker run -ti -p 9000:9000 \
34 | -e DEMO_USERNAME=secrethub://${SECRETHUB_USERNAME}/demo/username \
35 | -e DEMO_PASSWORD=secrethub://${SECRETHUB_USERNAME}/demo/password \
36 | -e SECRETHUB_CREDENTIAL=$(cat demo_service.cred) \
37 | play-secrethub-demo
38 | ```
39 |
40 | If you now visit http://localhost:9000, you should see the welcome message including your username.
41 |
42 |
--------------------------------------------------------------------------------
/application/play/java/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mozilla/sbt:latest
2 |
3 | # Install SecretHub
4 | RUN curl -sLJO https://deb.secrethub.io/amd64
5 | RUN dpkg -i secrethub-cli-amd64.deb
6 | RUN rm secrethub-cli-amd64.deb
7 |
8 | COPY example ./example/
9 |
10 | WORKDIR ./example/
11 |
12 | # Download project's dependencies
13 | RUN sbt update
14 |
15 | # Expose Play Framework standard port 9000
16 | EXPOSE 9000
17 |
18 | # Add the SecretHub entrypoint
19 | ENTRYPOINT ["secrethub", "run", "--"]
20 |
21 | # Start the main process
22 | CMD ["sbt", "run"]
23 |
24 |
--------------------------------------------------------------------------------
/application/play/java/example/.gitignore:
--------------------------------------------------------------------------------
1 | logs
2 | target
3 | /.idea
4 | /.idea_modules
5 | /.classpath
6 | /.project
7 | /.settings
8 | /RUNNING_PID
9 |
--------------------------------------------------------------------------------
/application/play/java/example/app/controllers/HomeController.java:
--------------------------------------------------------------------------------
1 | package controllers;
2 |
3 | import play.mvc.*;
4 |
5 | /**
6 | * This controller contains an action to handle HTTP requests
7 | * to the application's home page.
8 | */
9 | public class HomeController extends Controller {
10 |
11 | /**
12 | * An action that renders an HTML page with a welcome message.
13 | * The configuration in the routes file means that
14 | * this method will be called when the application receives a
15 | * GET request with a path of /.
16 | */
17 | public Result index() {
18 | if (System.getenv("DEMO_USERNAME") == null || System.getenv("DEMO_PASSWORD") == null) {
19 | return Results.internalServerError("not all variables are set\n");
20 | } else {
21 | return ok("Welcome " + System.getenv("DEMO_USERNAME") + "\n");
22 | }
23 | }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/application/play/java/example/build.sbt:
--------------------------------------------------------------------------------
1 | name := """example"""
2 | organization := "com.example"
3 |
4 | version := "1.0-SNAPSHOT"
5 |
6 | lazy val root = (project in file(".")).enablePlugins(PlayJava)
7 |
8 | scalaVersion := "2.13.3"
9 |
10 | libraryDependencies += guice
11 |
--------------------------------------------------------------------------------
/application/play/java/example/conf/application.conf:
--------------------------------------------------------------------------------
1 | # This is the main configuration file for the application.
2 | # https://www.playframework.com/documentation/latest/ConfigFile
3 |
--------------------------------------------------------------------------------
/application/play/java/example/conf/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | ${application.home:-.}/logs/application.log
8 |
9 | UTF-8
10 |
11 | %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{akkaSource}) %msg%n
12 |
13 |
14 |
15 |
16 |
17 | true
18 |
19 | UTF-8
20 |
21 | %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{akkaSource}) %msg%n
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/application/play/java/example/conf/routes:
--------------------------------------------------------------------------------
1 | # Routes
2 | # This file defines all application routes (Higher priority routes first)
3 | # ~~~~
4 |
5 | # An example controller showing a sample home page
6 | GET / controllers.HomeController.index
7 |
8 | # Map static resources from the /public folder to the /assets URL path
9 | GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
10 |
--------------------------------------------------------------------------------
/application/play/java/example/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version=1.3.13
2 |
--------------------------------------------------------------------------------
/application/play/java/example/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | // The Play plugin
2 | addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")
3 |
4 | // Defines scaffolding (found under .g8 folder)
5 | // http://www.foundweekends.org/giter8/scaffolding.html
6 | // sbt "g8Scaffold form"
7 | addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.11.0")
8 |
--------------------------------------------------------------------------------
/application/play/java/example/test/controllers/HomeControllerTest.java:
--------------------------------------------------------------------------------
1 | package controllers;
2 |
3 | import org.junit.Test;
4 | import play.Application;
5 | import play.inject.guice.GuiceApplicationBuilder;
6 | import play.mvc.Http;
7 | import play.mvc.Result;
8 | import play.test.WithApplication;
9 |
10 | import static org.junit.Assert.assertEquals;
11 | import static play.mvc.Http.Status.*;
12 | import static play.test.Helpers.GET;
13 | import static play.test.Helpers.route;
14 |
15 | public class HomeControllerTest extends WithApplication {
16 |
17 | @Override
18 | protected Application provideApplication() {
19 | return new GuiceApplicationBuilder().build();
20 | }
21 |
22 | @Test
23 | public void testIndex() {
24 | Http.RequestBuilder request = new Http.RequestBuilder()
25 | .method(GET)
26 | .uri("/");
27 |
28 | Result result = route(app, request);
29 | if (System.getenv("DEMO_USERNAME") == null || System.getenv("DEMO_PASSWORD") == null) {
30 | assertEquals(INTERNAL_SERVER_ERROR, result.status());
31 | } else {
32 | assertEquals(OK, result.status());
33 | }
34 | }
35 |
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/application/play/scala/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mozilla/sbt:latest
2 |
3 | # Install SecretHub
4 | RUN curl -sLJO https://deb.secrethub.io/amd64
5 | RUN dpkg -i secrethub-cli-amd64.deb
6 | RUN rm secrethub-cli-amd64.deb
7 |
8 | COPY example ./example/
9 |
10 | WORKDIR ./example/
11 |
12 | # Download project's dependencies
13 | RUN sbt update
14 |
15 | # Expose Play Framework standard port 9000
16 | EXPOSE 9000
17 |
18 | # Add the SecretHub entrypoint
19 | ENTRYPOINT ["secrethub", "run", "--"]
20 |
21 | # Start the main process
22 | CMD ["sbt", "run"]
23 |
24 |
--------------------------------------------------------------------------------
/application/play/scala/example/.gitignore:
--------------------------------------------------------------------------------
1 | logs
2 | target
3 | /.idea
4 | /.idea_modules
5 | /.classpath
6 | /.project
7 | /.settings
8 | /RUNNING_PID
9 |
--------------------------------------------------------------------------------
/application/play/scala/example/app/controllers/HomeController.scala:
--------------------------------------------------------------------------------
1 | package controllers
2 |
3 | import javax.inject._
4 | import play.api._
5 | import play.api.mvc._
6 |
7 | /**
8 | * This controller creates an `Action` to handle HTTP requests to the
9 | * application's home page.
10 | */
11 | @Singleton
12 | class HomeController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {
13 |
14 | /**
15 | * Create an Action to render an HTML page.
16 | *
17 | * The configuration in the `routes` file means that this method
18 | * will be called when the application receives a `GET` request with
19 | * a path of `/`.
20 | */
21 | def index() = Action { implicit request: Request[AnyContent] =>
22 | if (sys.env.getOrElse("DEMO_USERNAME", "").isEmpty || sys.env.getOrElse("DEMO_PASSWORD", "").isEmpty) {
23 | InternalServerError("not all variables are set\n")
24 | } else {
25 | Ok("Welcome " + sys.env("DEMO_USERNAME") + "\n")
26 | }
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/application/play/scala/example/build.sbt:
--------------------------------------------------------------------------------
1 | name := """example"""
2 | organization := "com.example"
3 |
4 | version := "1.0-SNAPSHOT"
5 |
6 | lazy val root = (project in file(".")).enablePlugins(PlayScala)
7 |
8 | scalaVersion := "2.13.3"
9 |
10 | libraryDependencies += guice
11 | libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
12 |
13 | // Adds additional packages into Twirl
14 | //TwirlKeys.templateImports += "com.example.controllers._"
15 |
16 | // Adds additional packages into conf/routes
17 | // play.sbt.routes.RoutesKeys.routesImport += "com.example.binders._"
18 |
--------------------------------------------------------------------------------
/application/play/scala/example/conf/application.conf:
--------------------------------------------------------------------------------
1 | # https://www.playframework.com/documentation/latest/Configuration
2 |
--------------------------------------------------------------------------------
/application/play/scala/example/conf/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | ${application.home:-.}/logs/application.log
8 |
9 | UTF-8
10 |
11 | %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{akkaSource}) %msg%n
12 |
13 |
14 |
15 |
16 |
17 | true
18 |
19 | UTF-8
20 |
21 | %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{akkaSource}) %msg%n
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/application/play/scala/example/conf/messages:
--------------------------------------------------------------------------------
1 | # https://www.playframework.com/documentation/latest/ScalaI18N
2 |
--------------------------------------------------------------------------------
/application/play/scala/example/conf/routes:
--------------------------------------------------------------------------------
1 | # Routes
2 | # This file defines all application routes (Higher priority routes first)
3 | # https://www.playframework.com/documentation/latest/ScalaRouting
4 | # ~~~~
5 |
6 | # An example controller showing a sample home page
7 | GET / controllers.HomeController.index
8 |
9 | # Map static resources from the /public folder to the /assets URL path
10 | GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
11 |
--------------------------------------------------------------------------------
/application/play/scala/example/project/build.properties:
--------------------------------------------------------------------------------
1 | sbt.version=1.3.13
2 |
--------------------------------------------------------------------------------
/application/play/scala/example/project/plugins.sbt:
--------------------------------------------------------------------------------
1 | addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")
2 | addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.11.0")
3 |
--------------------------------------------------------------------------------
/application/play/scala/example/test/controllers/HomeControllerSpec.scala:
--------------------------------------------------------------------------------
1 | package controllers
2 |
3 | import org.scalatestplus.play._
4 | import org.scalatestplus.play.guice._
5 | import play.api.test._
6 | import play.api.test.Helpers._
7 |
8 | /**
9 | * Add your spec here.
10 | * You can mock out a whole application including requests, plugins etc.
11 | *
12 | * For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest
13 | */
14 | class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {
15 |
16 | def checkCredentials(negativeCase: Int): Int = {
17 | if (sys.env.getOrElse("DEMO_USERNAME", "").isEmpty || sys.env.getOrElse("DEMO_PASSWORD", "").isEmpty) negativeCase
18 | else OK
19 | }
20 |
21 | def credentialMessage(): String = {
22 | if (sys.env.getOrElse("DEMO_USERNAME", "").isEmpty || sys.env.getOrElse("DEMO_PASSWORD", "").isEmpty) "not all variables are set"
23 | else "Welcome"
24 | }
25 |
26 | def routeContentType(): Some[String] = {
27 | if (sys.env.getOrElse("DEMO_USERNAME", "").isEmpty || sys.env.getOrElse("DEMO_PASSWORD", "").isEmpty) Some("text/html")
28 | else Some("text/plain")
29 | }
30 |
31 | def routeCredentialMessage(): String = {
32 | if (sys.env.getOrElse("DEMO_USERNAME", "").isEmpty || sys.env.getOrElse("DEMO_PASSWORD", "").isEmpty) "Not Found"
33 | else "Welcome"
34 | }
35 |
36 | "HomeController GET" should {
37 |
38 | "render the index page from a new instance of controller" in {
39 | val controller = new HomeController(stubControllerComponents())
40 | val home = controller.index().apply(FakeRequest(GET, "/"))
41 |
42 | status(home) mustBe checkCredentials(INTERNAL_SERVER_ERROR)
43 | contentType(home) mustBe Some("text/plain")
44 | contentAsString(home) must include (credentialMessage())
45 | }
46 |
47 | "render the index page from the application" in {
48 | val controller = inject[HomeController]
49 | val home = controller.index().apply(FakeRequest(GET, "/"))
50 |
51 | status(home) mustBe checkCredentials(INTERNAL_SERVER_ERROR)
52 | contentType(home) mustBe Some("text/plain")
53 | contentAsString(home) must include (credentialMessage())
54 | }
55 |
56 | "render the index page from the router" in {
57 | val request = FakeRequest(GET, "/")
58 | val home = route(app, request).get
59 |
60 | status(home) mustBe checkCredentials(NOT_FOUND)
61 | contentType(home) mustBe routeContentType()
62 | contentAsString(home) must include (routeCredentialMessage())
63 | }
64 | }
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/application/rails/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:2.7
2 | RUN mkdir /myapp
3 | WORKDIR /myapp
4 |
5 | # Install SecretHub
6 | RUN echo "deb [trusted=yes] https://apt.secrethub.io stable main" > /etc/apt/sources.list.d/secrethub.sources.list && apt-get update
7 | RUN apt-get install -y secrethub-cli
8 |
9 | # Install rails
10 | RUN gem install rails
11 |
12 | # Create Secrethub Demo app
13 | RUN rails new secrethub_demo --api --skip-active-record
14 |
15 | # Copy source files
16 | COPY routes.rb /myapp/secrethub_demo/config/routes.rb
17 | COPY application_controller.rb /myapp/secrethub_demo/app/controllers/application_controller.rb
18 |
19 | # Change workdir
20 | WORKDIR /myapp/secrethub_demo/
21 |
22 | # Expose rails standard port
23 | EXPOSE 3000
24 |
25 | # Add the secrethub entrypoint
26 | ENTRYPOINT ["secrethub", "run", "--"]
27 |
28 | # Start the main process
29 | CMD ["rails", "server", "-b", "0.0.0.0"]
30 |
--------------------------------------------------------------------------------
/application/rails/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | This Ruby on Rails example checks if the environment variables `DEMO_USERNAME` and `DEMO_PASSWORD` have been set. If that's the case, you'll receive a `200` on http://localhost:8080 and if it's not, you'll get a `500`.
7 |
8 | ## Prerequisites
9 | 1. [Docker](https://docs.docker.com/install/) installed and running
10 | 1. [SecretHub](https://secrethub.io/docs/start/getting-started/#install) installed
11 | 1. A SecretHub repo that contains a `username` and `password` secret. To create it, run `secrethub demo init`.
12 |
13 | ## Running the example
14 |
15 | Set the SecretHub username in an environment variable
16 | ```
17 | export SECRETHUB_USERNAME=
18 | ```
19 |
20 | Create a service account for the demo repo
21 | ```
22 | secrethub service init --description demo_service \
23 | --permission read --file demo_service.cred ${SECRETHUB_USERNAME}/demo
24 | ```
25 |
26 | Build the rails docker demo
27 | ```
28 | docker build . -t rails-secrethub-demo
29 | ```
30 |
31 | Run the docker demo with the secrets in the environment variables
32 | ```
33 | docker run -ti -p 8080:3000 \
34 | -e DEMO_USERNAME=secrethub://${SECRETHUB_USERNAME}/demo/username \
35 | -e DEMO_PASSWORD=secrethub://${SECRETHUB_USERNAME}/demo/password \
36 | -e SECRETHUB_CREDENTIAL=$(cat demo_service.cred) \
37 | rails-secrethub-demo
38 | ```
39 |
40 | If you now visit http://localhost:8080, you should see the welcome message including your username.
41 |
--------------------------------------------------------------------------------
/application/rails/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::API
2 | def index
3 | if ENV['DEMO_USERNAME'] && ENV['DEMO_PASSWORD']
4 | render status: 200, html: "Welcome " + ENV['DEMO_USERNAME']
5 | else
6 | render status: 500, html: 'not all variables are set'
7 | end
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/application/rails/routes.rb:
--------------------------------------------------------------------------------
1 | # config/routes.rb
2 | Rails.application.routes.draw do
3 | root to: 'application#index'
4 | end
5 |
--------------------------------------------------------------------------------
/application/ruby/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:2.7-slim
2 | WORKDIR /app
3 | COPY . /app
4 |
5 | # Install SecretHub
6 | RUN echo "deb [trusted=yes] https://apt.secrethub.io stable main" > /etc/apt/sources.list.d/secrethub.sources.list && apt-get update
7 | RUN apt-get install -y secrethub-cli
8 |
9 | # Install Gemfile
10 | RUN bundle update
11 | RUN bundle install
12 |
13 | # Expose ruby standard port 4567
14 | EXPOSE 4567
15 |
16 | # Add the secrethub entrypoint
17 | ENTRYPOINT ["secrethub", "run", "--"]
18 |
19 | # Start the main process
20 | CMD ["ruby", "myapp.rb"]
21 |
--------------------------------------------------------------------------------
/application/ruby/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | gem 'sinatra'
4 | gem 'sinatra-contrib'
5 |
--------------------------------------------------------------------------------
/application/ruby/README.md:
--------------------------------------------------------------------------------
1 | # Ruby application in Docker
2 |
3 | This Ruby example checks if the environment variables `DEMO_USERNAME` and `DEMO_PASSWORD` have been set. If that's the case, you'll receive a `200` on http://localhost:8080 and if it's not, you'll get a `500`.
4 |
5 | ## Prerequisites
6 | 1. [Docker](https://docs.docker.com/install/) installed and running
7 | 1. [SecretHub](https://secrethub.io/docs/start/getting-started/#install) installed
8 | 1. A SecretHub repo that contains a `username` and `password` secret. To create it, run `secrethub demo init`.
9 |
10 | ## Running the example
11 |
12 | Set the SecretHub username in an environment variable
13 | ```
14 | export SECRETHUB_USERNAME=
15 | ```
16 |
17 | Create a service account for the demo repo
18 | ```
19 | secrethub service init --description demo_service \
20 | --permission read --file demo_service.cred ${SECRETHUB_USERNAME}/demo
21 | ```
22 |
23 | Build the ruby docker demo
24 | ```
25 | docker build . -t ruby-secrethub-demo
26 | ```
27 |
28 | Run the docker demo with the secrets in the environment variables
29 | ```
30 | docker run -ti -p 8080:4567 \
31 | -e DEMO_USERNAME=secrethub://${SECRETHUB_USERNAME}/demo/username \
32 | -e DEMO_PASSWORD=secrethub://${SECRETHUB_USERNAME}/demo/password \
33 | -e SECRETHUB_CREDENTIAL=$(cat demo_service.cred) \
34 | ruby-secrethub-demo
35 | ```
36 |
37 | If you now visit http://localhost:8080, you should see the welcome message including your username.
38 |
--------------------------------------------------------------------------------
/application/ruby/myapp.rb:
--------------------------------------------------------------------------------
1 | # myapp.rb
2 | require 'sinatra'
3 |
4 | port = ENV['PORT'] || 4567
5 | puts "Starting ruby-secrethub-demo on port #{port}"
6 | set :port, port
7 | set :bind, '0.0.0.0'
8 |
9 | if ENV['DEMO_USERNAME'] && ENV['DEMO_PASSWORD']
10 | status = 200
11 | content = "Welcome " + ENV['DEMO_USERNAME']
12 | else
13 | status = 500
14 | content = 'not all variables are set'
15 | end
16 |
17 | get '/' do
18 | status status
19 | body content
20 | end
21 |
--------------------------------------------------------------------------------
/application/spring-boot/Dockerfile:
--------------------------------------------------------------------------------
1 | # Build app using Maven
2 | FROM maven:3-jdk-8 AS build
3 |
4 | WORKDIR /build
5 |
6 | COPY pom.xml .
7 |
8 | RUN mvn dependency:resolve
9 |
10 | COPY src/ src/
11 |
12 | RUN mvn package
13 |
14 | # Run app
15 | FROM openjdk:8-jdk-alpine
16 | COPY --from=build /build/target/example-*.jar /example.jar
17 |
18 | # Install SecretHub
19 | RUN apk add --repository https://alpine.secrethub.io/alpine/edge/main --allow-untrusted secrethub-cli
20 |
21 | # Expose spring boot standard port 8080
22 | EXPOSE 8080
23 |
24 | # Add the SecretHub entrypoint
25 | ENTRYPOINT ["secrethub", "run", "--"]
26 |
27 | # Start the main process
28 | CMD ["java", "-jar", "/example.jar"]
29 |
--------------------------------------------------------------------------------
/application/spring-boot/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | This Spring Boot example checks if the environment variables `DEMO_USERNAME` and `DEMO_PASSWORD` have been set. If that's the case, you'll receive a `200` on http://localhost:8080 and if it's not, you'll get a `500`.
7 |
8 | ## Prerequisites
9 | 1. [Docker](https://docs.docker.com/install/) installed and running
10 | 1. [SecretHub](https://secrethub.io/docs/start/getting-started/#install) installed
11 | 1. A SecretHub repo that contains a `username` and `password` secret. To create it, run `secrethub demo init`.
12 |
13 | ## Running the example
14 |
15 | Set the SecretHub username in an environment variable
16 | ```
17 | export SECRETHUB_USERNAME=
18 | ```
19 |
20 | Create a service account for the demo repo
21 | ```
22 | secrethub service init --description demo_service \
23 | --permission read --file demo_service.cred ${SECRETHUB_USERNAME}/demo
24 | ```
25 |
26 | Build the spring-boot docker demo
27 | ```
28 | docker build . -t spring-secrethub-demo
29 | ```
30 |
31 | Run the docker demo with the secrets in the environment variables
32 | ```
33 | docker run -ti -p 8080:8080 \
34 | -e DEMO_USERNAME=secrethub://${SECRETHUB_USERNAME}/demo/username \
35 | -e DEMO_PASSWORD=secrethub://${SECRETHUB_USERNAME}/demo/password \
36 | -e SECRETHUB_CREDENTIAL=$(cat demo_service.cred) \
37 | spring-secrethub-demo
38 | ```
39 |
40 | If you now visit http://localhost:8080, you should see the welcome message including your username.
41 |
--------------------------------------------------------------------------------
/application/spring-boot/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework
7 | example
8 | 0.1.0
9 |
10 |
11 | org.springframework.boot
12 | spring-boot-starter-parent
13 | 2.2.1.RELEASE
14 |
15 |
16 |
17 | 1.8
18 |
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-test
28 | test
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-maven-plugin
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/application/spring-boot/src/main/java/example/ExampleApplication.java:
--------------------------------------------------------------------------------
1 | package example;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.http.HttpStatus;
7 | import org.springframework.boot.autoconfigure.SpringBootApplication;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 |
12 | @SpringBootApplication
13 | public class ExampleApplication {
14 |
15 | @Value("${DEMO_USERNAME:#{null}}")
16 | String username;
17 |
18 | @Value("${DEMO_PASSWORD:#{null}}")
19 | String password;
20 |
21 | @RestController
22 | class ExampleController {
23 | @GetMapping("/")
24 | ResponseEntity printSecrets() {
25 | if (username==null || password==null) {
26 | return new ResponseEntity<>("not all variables are set", HttpStatus.INTERNAL_SERVER_ERROR);
27 | } else {
28 | return new ResponseEntity<>("Welcome " + username, HttpStatus.OK);
29 | }
30 | }
31 | }
32 |
33 | public static void main(String[] args) {
34 | SpringApplication.run(ExampleApplication.class, args);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/aws/ec2/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | This example uses Terraform to launch an EC2 instance, deploy the [SecretHub Demo App](https://secrethub.io/docs/start/getting-started/#consume) on it and provision it with the required secrets using the [SecretHub AWS Identity Provider](https://secrethub.io/docs/reference/aws/).
12 |
13 | ## Prerequisites
14 | 1. [Terraform](https://www.terraform.io/downloads.html) installed along with the [SecretHub Provider](https://secrethub.io/docs/guides/terraform/#install)
15 | 1. Correctly configured [AWS Credentials](https://www.terraform.io/docs/providers/aws/index.html#authentication)
16 | 1. [Values assigned](https://www.terraform.io/docs/configuration/variables.html#assigning-values-to-root-module-variables) to the variables in [variables.tf](./variables.tf)
17 |
18 | ## Running the example
19 |
20 | To launch an example EC2 instance (`t2.nano`), that runs the demo app, run:
21 | ```
22 | terraform init
23 | terraform apply
24 | ```
25 |
26 | Once the instance is running its public IP will be outputted.
27 |
28 | To see the app running, visit `http://:8080`.
29 |
30 | > Note that it might take a couple minutes for the instance to be accessible from the browser.
31 |
--------------------------------------------------------------------------------
/aws/ec2/app.tf:
--------------------------------------------------------------------------------
1 | resource "aws_iam_role" "secrethub_demo" {
2 | name = "SecretHubDemoEC2Role"
3 | assume_role_policy = data.aws_iam_policy_document.ec2_assume_role.json
4 | description = "Role for SecretHub demo app"
5 | }
6 |
7 | data "aws_iam_policy_document" "ec2_assume_role" {
8 | statement {
9 | actions = ["sts:AssumeRole"]
10 |
11 | principals {
12 | type = "Service"
13 | identifiers = ["ec2.amazonaws.com"]
14 | }
15 | }
16 | }
17 |
18 | resource "aws_kms_key" "secrethub_auth" {
19 | description = "KMS key to facilitate SecretHub authentication"
20 | }
21 |
22 | data "aws_iam_policy_document" "secrethub_auth" {
23 | statement {
24 | actions = ["kms:Decrypt"]
25 | resources = [aws_kms_key.secrethub_auth.arn]
26 | effect = "Allow"
27 | }
28 | }
29 |
30 | resource "aws_iam_policy" "secrethub_auth" {
31 | name = "SecretHubAuth"
32 | description = "Allow SecretHub authentication using KMS"
33 | policy = data.aws_iam_policy_document.secrethub_auth.json
34 | }
35 |
36 | resource "aws_iam_role_policy_attachment" "secrethub_demo_auth" {
37 | role = aws_iam_role.secrethub_demo.name
38 | policy_arn = aws_iam_policy.secrethub_auth.arn
39 | }
40 |
41 | resource "secrethub_service_aws" "demo_app" {
42 | repo = var.secrethub_repo
43 | role = aws_iam_role.secrethub_demo.name
44 | kms_key_arn = aws_kms_key.secrethub_auth.arn
45 | }
46 |
47 | resource "secrethub_access_rule" "demo_app" {
48 | account_name = secrethub_service_aws.demo_app.id
49 | dir = var.secrethub_repo
50 | permission = "read"
51 | }
52 |
53 | data "aws_ami" "amazon_linux" {
54 | owners = ["amazon"]
55 | most_recent = true
56 |
57 | filter {
58 | name = "name"
59 | values = ["amzn-ami-hvm-*-x86_64-gp2"]
60 | }
61 | }
62 |
63 | resource "aws_instance" "secrethub_demo" {
64 | instance_type = "t2.nano"
65 | ami = data.aws_ami.amazon_linux.id
66 | iam_instance_profile = aws_iam_instance_profile.secrethub_demo.name
67 | security_groups = [aws_security_group.secrethub_demo.name]
68 | associate_public_ip_address = true
69 | user_data = <<-EOT
70 | #! /bin/bash
71 | sudo curl https://yum.secrethub.io/secrethub.repo --output /etc/yum/repos.d/secrethub.repo --create-dirs
72 | sudo yum install -y secrethub-cli
73 | export DEMO_USERNAME=secrethub://${var.secrethub_repo}/username
74 | export DEMO_PASSWORD=secrethub://${var.secrethub_repo}/password
75 | secrethub run --identity-provider=aws -- secrethub demo serve --host 0.0.0.0 --port ${var.port}
76 | EOT
77 | }
78 |
79 | resource "aws_iam_instance_profile" "secrethub_demo" {
80 | role = aws_iam_role.secrethub_demo.name
81 | }
82 |
83 | resource "aws_security_group" "secrethub_demo" {
84 | description = "SecretHub demo app"
85 |
86 | ingress {
87 | from_port = var.port
88 | to_port = var.port
89 | protocol = "tcp"
90 | cidr_blocks = ["0.0.0.0/0"]
91 | }
92 |
93 | egress {
94 | from_port = 0
95 | to_port = 0
96 | protocol = "-1"
97 | cidr_blocks = ["0.0.0.0/0"]
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/aws/ec2/main.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_providers {
3 | secrethub = {
4 | source = "secrethub/secrethub"
5 | version = "~> 1.2.3"
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/aws/ec2/outputs.tf:
--------------------------------------------------------------------------------
1 | output "public_ip" {
2 | value = aws_instance.secrethub_demo.public_ip
3 | }
4 |
--------------------------------------------------------------------------------
/aws/ec2/variables.tf:
--------------------------------------------------------------------------------
1 | variable "secrethub_repo" {
2 | description = "SecretHub repo that contains the demo `username` and `password` secrets. To create this repo, run `secrethub demo init`."
3 | }
4 |
5 | variable "port" {
6 | description = "Port to publicly expose on the EC2 node, where the demo app will listen on."
7 | default = 8080
8 | }
9 |
--------------------------------------------------------------------------------
/aws/ecs/README.md:
--------------------------------------------------------------------------------
1 |