Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Import secretes from secrets.yml #735

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ yarn-error.log*

# App configuration
config.yml
secrets.yml

.drone.yml
26 changes: 26 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,29 @@ The `/assets/manifest.json` can also be edited to change the app (pwa) name, des
## PWA Icons

See icons documentation [here](https://github.com/bastienwirtz/homer/blob/main/public/assets/icons/README.md).


## Importing Secrets

You can import sensitive information such as API keys or passwords into your `config.yml` file securely using the `!secret` keyword. The corresponding tokens are stored in the `secrets.yml` file. This approach allows you to keep confidential information separate, eliminating the need to expose sensitive information directly in your configuration.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This secret file is as public as the main config file. Having it separated can help manage the secrets, but it does not add any security.



### Example:

In your `secrets.yml` file:

```yaml
api_key: your_super_secret_api_key
db_password: your_secure_database_password
```

In your `config.yml` file:

```yaml
services:
- name: "Example Service"
api_key: !secret api_key
database:
password: !secret db_password
# ...
```
6 changes: 3 additions & 3 deletions public/assets/config-demo.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ services:
node: "node1"
warning_value: 50
danger_value: 80
api_token: "xxxxxxxxxxxx"
api_token: !secret proxmox_api
- name: "An awesome app"
logo: "assets/tools/sample.png"
subtitle: "Bookmark example"
Expand All @@ -95,7 +95,7 @@ services:
items:
- name: "Octoprint"
logo: "https://cdn-icons-png.flaticon.com/512/3112/3112529.png"
apikey: "xxxxxxxxxxxx"
apikey: !secret octoprint_api
endpoint: "https://homer-demo-content.netlify.app/octoprint"
type: "OctoPrint"
- name: "Example item"
Expand All @@ -107,7 +107,7 @@ services:
target: "_blank"
- name: "Weather"
location: "Lyon"
apikey: "xxxxxxxxxxxx" # insert your own API key here. Request one from https://openweathermap.org/api.
apikey: !secret weather_api # insert your own API key here. Request one from https://openweathermap.org/api.
units: "metric"
endpoint: "https://homer-demo-content.netlify.app/openweather/weather"
type: "OpenWeather"
Expand Down
4 changes: 4 additions & 0 deletions public/assets/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
some_password: welcome # include it in your config.yml by using !secret some_password
proxmox_api: xxxxxxxxxxxx
octoprint_api: xxxxxxxxxxxx
weather_api: xxxxxxxxxxxx
19 changes: 18 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,24 @@ export default {
return response
.text()
.then((body) => {
return parse(body, { merge: true });
return fetch("assets/secrets.yml")
.then((secretsResponse) => {
if (secretsResponse.status == 404 || secretsResponse.redirected) {
return {};
}
if (!secretsResponse.ok) {
throw Error(`${secretsResponse.statusText}: ${secretsResponse.body}`);
}
return secretsResponse.text();
})
.then((secretsText) => {
const secrets = parse(secretsText);
let replacedBody = body;
Object.entries(secrets).forEach(([key, token]) => {
replacedBody = replacedBody.replace(new RegExp(`!secret ${key}`, "g"), token);
});
return parse(replacedBody, { merge: true });
});
})
.then(function (config) {
if (config.externalConfig) {
Expand Down