Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit b4ad89b

Browse files
wilsonianbalexellis
authored andcommitted
Mount public key to dashboard as secret
Signed-off-by: Brandon Wilson <brandon@coil.com>
1 parent d630bf7 commit b4ad89b

File tree

6 files changed

+39
-59
lines changed

6 files changed

+39
-59
lines changed

dashboard/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ $ faas-cli store deploy nodeinfo --name alexellis-nodeinfo \
3939
--annotation com.openfaas.cloud.git-repo-url=https://github.com/alexellis/nodeinfo
4040
```
4141

42+
### Deploy SealedSecrets public key
43+
44+
The dashboard serves the SealedSecrets public key file in `/var/openfaas/secrets/pub-cert.pem`.
45+
46+
To mount the key in Kubernetes, run:
47+
48+
```
49+
$ kubectl create secret generic sealedsecrets-public-key -n openfaas-fn --from-file=pub-cert.pem
50+
```
51+
4252
### Deploy at least the list-functions function
4353

4454
From the root directory edit `gateway_config.yml`, if on Swarm remove any `.openfaas` suffix you see in URLs.
@@ -106,7 +116,7 @@ npm i -g yarn
106116
The source code for the dashboard (written in React.js) with Bootstrap 3 has to be built into a generated folder. In order to do this type in `make`
107117

108118
```bash
109-
make
119+
make build-dist
110120
```
111121

112122
You will see new files written into `of-cloud-dashboard/dist`

dashboard/client/public/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
window.ALL_CLAIMS = '__ALL_CLAIMS__';
2121
window.GITHUB_APP_URL = '__GITHUB_APP_URL__';
2222
window.GITLAB_URL = '__GITLAB_URL__';
23-
window.PUBLIC_KEY_EXISTS = '__PUBLIC_KEY_EXISTS__';
2423
</script>
2524
</head>
2625

dashboard/client/src/components/NavBar/NavBar.jsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,16 @@ class NavBarWithRouter extends Component {
118118
</NavLink>
119119
</NavItem>
120120
}
121-
{ window.PUBLIC_KEY_EXISTS &&
122-
<NavItem>
123-
<NavLink
124-
className="py-3 px-3 px-md-2"
125-
href="dist/pub-cert.pem"
126-
title="Encrypt function secrets for use in your git repository"
127-
>
128-
<FontAwesomeIcon icon={faKey} className="mr-1" />
129-
Public Key
130-
</NavLink>
131-
</NavItem>
132-
}
121+
<NavItem>
122+
<NavLink
123+
className="py-3 px-3 px-md-2"
124+
href="api/pub-cert.pem"
125+
title="Encrypt function secrets for use in your git repository"
126+
>
127+
<FontAwesomeIcon icon={faKey} className="mr-1" />
128+
Public Key
129+
</NavLink>
130+
</NavItem>
133131
</Nav>
134132
<Nav navbar className="ml-auto">
135133
{ this.isLoggedIn() && this.createNavLink(

dashboard/dashboard_config.yml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,4 @@ environment:
1616
# see https://github.com/settings/apps/
1717
# github_app_url: https://github.com/apps/o6s-io
1818
# Public URL for your GitLab instance
19-
# gitlab_url: https://gitlab.o6s.io/
20-
# SealedSecrets public key
21-
# public_key: |
22-
# -----BEGIN CERTIFICATE-----
23-
# MIIErjCCApagAwIBAgIRAOpOnJ35KXJmoda4VjnxqgIwDQYJKoZIhvcNAQELBQAw
24-
# ADAeFw0yMDEwMjAyMzE5MzhaFw0zMDEwMTgyMzE5MzhaMAAwggIiMA0GCSqGSIb3
25-
# DQEBAQUAA4ICDwAwggIKAoICAQC1RNAnJC850lP00fWJVGs7y/AaWU08eitNmqgm
26-
# VkRg04baGLSOIwv5aMzHe68e1bZUAa3NzhL7lKEJdgU4+G0eidVjg4hngVvPfaCy
27-
# o6OYU+f9rTDTwOihwOu1rGBUrG42S8niWJpfDMmzyFgG/AZAJfiYOK6/FIP0JoZB
28-
# JQqorJvsmdrhve+LlwUlFIBj9cP5mWQ2OlrM49QV2rlauJfR8UEwQxsQYmxDrKxe
29-
# NltLrrsSVqqarcOCE7vHlnV+YoBK9CEAu4nCjCDV3B8fRI3ODoO5twAGJ21NeVKm
30-
# OeqgDm48lViol3F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0DzkzZxOKooesNe+j5nx
46-
# jHP/isiGskK0EdOVetJN+FuDo0Ys+Ev/d7vAyy32WIcnTfbJ7nAHnhvhPCDp05F3
47-
# aAgXn0ahlcFp/HqzyD+hxPKszH1NG0WXEXIhNBr+1MoGlwTJ+PIp9oY4wt5SoKcz
48-
# rl4=
49-
# -----END CERTIFICATE-----
19+
# gitlab_url: https://gitlab.o6s.io/

dashboard/of-cloud-dashboard/handler.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ module.exports = async (event, context) => {
6060
console.log(`${method} ${upstreamURL} - 500, error: ${err}`);
6161
return context.status(500).fail('Proxy request failed');
6262
}
63+
} else if (/^\/api\/pub-cert.pem\/?$/.test(path)) {
64+
try {
65+
const pubKey = await fsPromises.readFile('/var/openfaas/secrets/pub-cert.pem');
66+
const headers = {
67+
'Content-Type': 'text/plain',
68+
};
69+
return context
70+
.headers(headers)
71+
.status(200)
72+
.succeed(pubKey);
73+
} catch (err) {
74+
console.log(`GET /api/pub-cert.pem, error: ${err}`);
75+
return context.status(404).succeed('Not found');
76+
}
6377
}
6478

6579
let headers = {
@@ -76,18 +90,6 @@ module.exports = async (event, context) => {
7690
headers['Content-Type'] = 'application/json';
7791
} else if (/.*\.map/.test(path)) {
7892
headers['Content-Type'] = 'application/octet-stream';
79-
} else if (/^\/dist\/pub-cert.pem\/?$/.test(path)) {
80-
if (!process.env.public_key) {
81-
return context
82-
.status(404)
83-
.fail('Not found');
84-
}
85-
86-
headers['Content-Type'] = 'text/plain';
87-
return context
88-
.headers(headers)
89-
.status(200)
90-
.succeed(process.env.public_key);
9193
}
9294

9395
let contentPath = `${__dirname}${path}`;
@@ -141,7 +143,7 @@ module.exports = async (event, context) => {
141143
}
142144

143145
function replaceTokens(content, isSignedIn, claims) {
144-
const { base_href, public_url, pretty_url, query_pretty_url, github_app_url, gitlab_url, public_key } = process.env;
146+
const { base_href, public_url, pretty_url, query_pretty_url, github_app_url, gitlab_url } = process.env;
145147
let replaced = content
146148

147149
replaced = replaced.replace(/__BASE_HREF__/g, base_href);
@@ -152,7 +154,6 @@ function replaceTokens(content, isSignedIn, claims) {
152154
replaced = replaced.replace(/__ALL_CLAIMS__/g, claims);
153155
replaced = replaced.replace(/__GITHUB_APP_URL__/g, github_app_url || "");
154156
replaced = replaced.replace(/__GITLAB_URL__/g, gitlab_url || "");
155-
replaced = replaced.replace(/__PUBLIC_KEY_EXISTS__/g, public_key ? "true" : "");
156157

157158
return replaced
158159
}

dashboard/stack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ functions:
1313
role: openfaas-system
1414
environment_file:
1515
- dashboard/dashboard_config.yml
16+
secrets:
17+
- sealedsecrets-public-key
1618
limits:
1719
memory: 256Mi
1820
requests:

0 commit comments

Comments
 (0)