summaryrefslogtreecommitdiff
path: root/topics/gn-auth/generating-key-pairs.gmi
blob: 9fbcaa96d1b049abb271916c0a2288a824f23007 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Generating Key-Pairs

## Tags

* type: documentation
* keywords: doc, documentation, gn-auth, key-pair, jwt

## Generating the Key-Pair

If openssl is not present on your system, you need to get it. You can either install it with your package manager, or if you are using GNU Guix, you can do something like:

```
$ guix shell --container --network --share=</path/to/key-pair/storage/directory> openssl
```

where </path/to/key-pair/storage/directory> is where you will store the key-pairs.

Now we can generate a private key (2048-bit RSA key) with:

```
[env] $ openssl genrsa -out </path/to/key-pair/storage/directory>/private.pem 2048
```

and the public key with:

```
[env] $ openssl rsa \
      -in </path/to/key-pair/storage/directory>/private.pem \
      -outform PEM \
      -pubout \
      -out </path/to/key-pair/storage/directory>/public.pem
```

**NOTE**: You can store the public key separately from the private key. In that case, you'd have to have something like:

```
$ guix shell --container --network \
  --share=</path/to/public-key/storage/directory> \
  --share=</path/to/private-key/storage/directory> \
  openssl
```

and run the generation commands above with the appropriate directories in mind.

## Configuring Services

Now we need to configure the various services to make use of the key-pair.

For the client services (GN2, gn-uploader, etc), we only need to give access to the public key, so we can do:

```
# gn2.conf
︙
SSL_KEY_PAIR_PUBLIC_KEY = "</path/to/public-key/storage/directory>/public.pem"
︙
```

For the authorisation server (gn-auth), we need both:

```
# gn-auth.conf
SSL_KEY_PAIR_PUBLIC_KEY = "</path/to/public-key/storage/directory>/public.pem"
SSL_KEY_PAIR_PRIVATE_KEY = "</path/to/private-key/storage/directory>/private.pem"
```

## Exposing the Key-Pairs to Guix shell/container

The generated keys above do not need to be modified within the running application, so we will use the "--expose" option e.g.

```
$ guix system container \
  ︙
  --expose=</path/to/key-pair/storage/directory> \
  ︙
```

or if you stored the keys separately:

```
$ guix system container \
  ︙
  --expose=</path/to/public-key/storage/directory> \
  --expose=</path/to/private-key/storage/directory> \
  ︙
```