Skip to content

Commit 3e283ce

Browse files
tellieremmatthiesencsc
authored andcommitted
adding quickstart for hpcs server
1 parent 507738f commit 3e283ce

File tree

1 file changed

+258
-2
lines changed

1 file changed

+258
-2
lines changed

README.md

+258-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,263 @@ For docker-compose, we consider the Vault and the Spire Server as setup and the
211211

212212
#### K8s
213213

214-
WIP
214+
HPCS' serverside consists in an web API. The difficulty in the installation of it comes with the underlying services that needs to be available for it to run properly. Here is a scheme of the architecture of a fully-installed HPCS server side.
215+
216+
```mermaid
217+
flowchart LR
218+
219+
subgraph SSP[Spire Server pod]
220+
SSC[Spire Server container]
221+
SOC[Spire OIDC container]
222+
NC[Nginx proxy]
223+
end
224+
225+
SSS[Spire server service]
226+
VS[Vault service]
227+
228+
VP[Vault pod]
229+
230+
HP[HPCS server pod]
231+
232+
SSC <-- TCP:8081--> SSS
233+
NC <-- HTTPS:443--> SSS
234+
SSC <--UNIX Socket--> SOC
235+
SOC <--UNIX Socket--> NC
236+
SSS <--HTTPS:443--> VP
237+
HP <--TCP:8081--> SSS
238+
HP <--UNIX Socket--> SSC
239+
VS <--HTTP:8200--> VP
240+
HP <--HTTP:8200--> VS
241+
242+
Outside <--HTTP:anyport--> VS
243+
Outside <--TCP:anyport--> SSS
244+
```
245+
(Ports are specified for the serverside, clients ports used for communication doesn't matter)
246+
247+
This architecture comes in 3 different main parts :
248+
- HPCS Server (1 Container, containing Spire-Agent and HPCS Server)
249+
- Spire Server (3 Containers, spire-server, spire-oidc, and hpcs-nginx)
250+
- Vault (Helm chart, not managed by HPCS)
251+
252+
In order to proceed to the deployment of this architecture, k8s is the supported method, all the code associated is available under `/k8s`.
253+
254+
##### Pre-requisite
255+
256+
Before proceeding to HPCS' deployment, an original setup is required including :
257+
- A ready-to-run k8s cluster
258+
- `kubectl` and `helm` available and able to run kubernetes configurations (`.yaml`)
259+
- `rbac`, `storage` and `dns` and `helm` kubernetes capabilities, f.e : `microk8s enable rbac storage dns helm` with microk8s.
260+
261+
Please note down the name of your k8s cluster in order to run later deployments.
262+
263+
##### Configuration
264+
265+
Several configurations are to be reviewed before proceeding.
266+
- Nginx SSL Certificate path : Please review in `/k8s/spire-server-nginx-configmap.yaml` (section `ssl_certificate`) and `/k8s/spire-server-statefulset.yaml` (section `volumeMounts` of container `hpcs-nginx` and section `volumes` of the pod configuration). If you plan to run the deployment using ansible, please review `/k8s/deploy-all.yaml`, section `Copy oidc cert to vault's pod` and `Create spire-oidc {key, csr, cert}` for the host path to the certificate. Create the directory configured before running deployment.
267+
268+
- Cluster name : Please review in `/k8s/hpcs-server-configmap.yaml`, section "`agent.conf`", then "`k8s_psat`" and `/k8s/spire-server-configmap.yaml`, section "`server.conf`", then "`k8s_psat`", replace "`docker-desktop`" with your k8s cluster name.
269+
270+
- For further information about spire agent/ server configurations under `/k8s/hpcs-server-configmap.yaml` and `/k8s/spire-server-configmap.yaml`, please refer to spire-server [configuration reference](https://spiffe.io/docs/latest/deploying/spire_server) and spire-agent [configuration reference](https://spiffe.io/docs/latest/deploying/spire_agent/).
271+
272+
273+
##### Bash
274+
275+
This part of the documentation walks you through the different steps necessary in order to run a manual deployment of HPCS' serverside (including Vault, Spire-Server and HPCS Server).
276+
277+
__Starting with the "`spire-server`" pods :__
278+
279+
Generate your nginx certificate :
280+
```bash
281+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /path/to/your/privatekey.key -out /path/to/your/certificate.crt -addext "subjectAltName = DNS:spire-oidc"
282+
```
283+
284+
Create HPCS namespace :
285+
```bash
286+
cd k8s
287+
kubectl apply -f hpcs-namespace.yaml
288+
```
289+
290+
Create Spire service account and cluster role :
291+
```bash
292+
kubectl apply -f spire-server-account.yaml -f spire-server-cluster-role.yaml
293+
```
294+
295+
Create configmaps for spire-server, spire-oidc and nginx proxy :
296+
```bash
297+
kubectl apply -f spire-oidc-configmap.yaml -f spire-server-configmap.yaml -f spire-server-nginx-configmap.yaml
298+
```
299+
300+
Create spire-server statefulset, managing spire-server-x pods :
301+
```bash
302+
kubectl apply -f spire-server-statefulset.yaml
303+
```
304+
305+
Expose spire-oidc proxy and spire-server's api over the cluster :
306+
```bash
307+
kubectl apply -f spire-server-service.yaml -f spire-oidc-service.yaml
308+
```
309+
310+
At this point, you should be able to see at least one `spire-server-x` pod, f.e :
311+
312+
```bash
313+
kubectl get -n hpcs pod/spire-server-0
314+
NAME READY STATUS RESTARTS AGE
315+
spire-server-0 3/3 Running 0 30s
316+
```
317+
318+
And the port on which the spire-server API is exposed (here 31140) :
319+
```bash
320+
kubectl get -n hpcs service/spire-server
321+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
322+
spire-server LoadBalancer 10.99.214.248 localhost 8081:31140/TCP 30s
323+
```
324+
325+
__Then install Hashicorp Vault via it's official helm chart (here with microk8s):__
326+
327+
Add hashicorp repo and run installation :
328+
```bash
329+
microk8s helm3 repo add hashicorp https://helm.releases.hashicorp.com
330+
helm install vault hashicorp/vault --version 0.27.0 --namespace=hpcs
331+
```
332+
333+
Initialize the Vault :
334+
```bash
335+
kubectl exec -it vault-0 -n hpcs -- vault operator init -n 1 -t 1
336+
```
337+
Note unseal token and root token.
338+
339+
Unseal vault :
340+
```bash
341+
kubectl exec -it vault-0 -n hpcs -- vault operator unseal [seal token]
342+
```
343+
344+
Connect to the vault to enable jwt auth and kvv2 secrets, register oidc as a source :
345+
```bash
346+
kubectl exec -it vault-0 -n hpcs -- sh
347+
export VAULT_TOKEN="[root token]"
348+
349+
# Enable kvv2
350+
vault secrets enable -version=2 kv
351+
352+
# Enable jwt auth
353+
vault auth enable jwt
354+
355+
# Connect OIDC authority (spire-oidc)
356+
vault write auth/jwt/config oidc_discovery_url=https://spire-oidc oidc_discovery_ca_pem="
357+
-----BEGIN CERTIFICATE-----
358+
...
359+
-----END CERTIFICATE-----
360+
"
361+
```
362+
363+
Expose Vault's API to the node :
364+
```bash
365+
kubectl expose service vault --name="vault-external" --type="NodePort" --target-port 8200 -n hpcs
366+
```
367+
368+
At this point, Vault is running and it's API is exposed, to check on which port, run :
369+
```bash
370+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
371+
vault-external NodePort 10.111.198.147 localhost 8200:31819/TCP,8201:31587/TCP 2s
372+
```
373+
374+
__Next step is to create a spire identity and it's vault role in order to be able to identify HPCS-Server against Vault__
375+
376+
Get your kubernetes node uid (repeat this and the following spire identity creation for every nodes):
377+
```bash
378+
kubectl get nodes -o json | grep uid
379+
```
380+
381+
Check wether you run containers using cgroupsv2 :
382+
```bash
383+
grep cgroup2 /proc/filesystems
384+
```
385+
386+
Create the spire identity (If not using cgroupsv2):
387+
```bash
388+
kubectl exec -n hpcs spire-server-0 -c spire-server -- ./bin/spire-server entry create -spiffeID spiffe://hpcs/hpcs-server/workload -parentID spiffe://hpcs/spire/agent/k8s_psat/[Cluster Name]/[UID] -selector k8s:pod-name:hpcs-server
389+
```
390+
391+
Create the spire identity (If using cgroupsv2):
392+
```bash
393+
kubectl exec -n hpcs spire-server-0 -c spire-server -- ./bin/spire-server entry create -spiffeID spiffe://hpcs/hpcs-server/workload -parentID spiffe://hpcs/spire/agent/k8s_psat/[Cluster Name]/[UID] -selector unix:uid:0
394+
```
395+
396+
Connect to vault and create hpcs-server policy :
397+
```bash
398+
> kubectl exec -it vault-0 -n hpcs -- sh
399+
/ $ vi /tmp/policy
400+
path "auth/jwt/role/*" {
401+
capabilities = ["sudo","read","create","delete","update"]
402+
}
403+
path "sys/policies/acl/*" {
404+
capabilities = ["sudo","read","create","delete","update"]
405+
}
406+
/ $ vault policy write hpcs-server /tmp/policy
407+
/ $ vault write auth/jwt/role/hpcs-server role_type=jwt user_claim=sub bound_audiences=TESTING bound_subject=spiffe://hpcs/hpcs-server/workload token_ttl=24h tok
408+
en_policies=hpcs-server
409+
```
410+
411+
__You can now deploy HPCS server__
412+
413+
Create hpcs-server and hpcs-spire service accounts :
414+
```bash
415+
kubectl apply -f hpcs-server-account.yaml -f hpcs-spire-account.yaml
416+
```
417+
418+
Create hpcs server configmap :
419+
```bash
420+
kubectl apply -f hpcs-server-configmap.yaml
421+
```
422+
423+
Create hpcs-server statefulset (and underlying pods) :
424+
```bash
425+
kubectl apply -f hpcs-server-statefulset.yaml
426+
```
427+
428+
Expose hpcs-server api over the cluster :
429+
```bash
430+
kubectl apply -f hpcs-server-service.yaml
431+
```
432+
433+
Expose hpcs-server service over the node :
434+
```bash
435+
kubectl expose service hpcs-server --name="hpcs-server-external" --type="NodePort" --target-port 10080 -n hpcs
436+
```
437+
438+
Check exposed port :
439+
```bash
440+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
441+
hpcs-server-external NodePort 10.111.198.151 localhost 10080:31827/TCP 2s
442+
```
443+
444+
That's it, you can now use HPCS server as you please.
445+
446+
##### Ansible
447+
448+
:warning: This method is currently still under development. You could run into non-documented issues.
449+
450+
The previously explained steps can be automatically run using an ansible playbook available under `/k8s/deploy-all.yaml`
451+
452+
All the pre-requisites listed before are necessary to run this playbook. If you are running kubernetes using `microk8s`, you will need to create aliases or fake commands for `helm`, for example using a script :
453+
```bash
454+
#!/bin/bash
455+
456+
microk8s helm3 $@
457+
```
458+
Written as `/usr/bin/helm`.
459+
460+
You will also need ansible k8s and openssl plugins :
461+
```bash
462+
ansible-galaxy collection install kubernetes.core
463+
ansible-galaxy collection install community.crypto
464+
```
465+
466+
You can now run the ansible playbook :
467+
```bash
468+
cd k8s
469+
ansible-playbook deploy-all.yaml
470+
```
215471

216472
#### Docker-compose
217473

@@ -366,4 +622,4 @@ When a client wants to encrypt its data or container and to give access to it to
366622
- Using cgroupsv2
367623
- Replacing every calling binary by the hypervisor
368624

369-
Since this limitation doesn't represent a confidentiality issue (a client isn't ever provided more than a write-only permission), current mitigations are more practical than secure (again, see #5).
625+
Since this limitation doesn't represent a confidentiality issue (a client isn't ever provided more than a write-only permission), current mitigations are more practical than secure (again, see #5).

0 commit comments

Comments
 (0)