Skip to content

Commit 15e7e05

Browse files
Fix gencert.sh and update related files (mattermost#7216)
* Update .gitignore to ignore key and crt, fix gencert.sh and update docs * Renamed gencert docs file & added to nav pane * Corrected gencert docs page link --------- Co-authored-by: Carrie Warner (Mattermost) <[email protected]>
1 parent 1ad07ce commit 15e7e05

File tree

6 files changed

+52
-25
lines changed

6 files changed

+52
-25
lines changed

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ source/developer/localization.md
6464

6565
# IDEs
6666
.idea/
67+
68+
# Generated PKI files
69+
*.key
70+
*.crt

Diff for: source/onboard/sso-saml-before-you-begin.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Before you begin
44
----------------
55

6-
Before you begin, you need generate encryption certificates for encrypting the SAML connection.
6+
Before you begin, you need to generate encryption certificates for encrypting the SAML connection.
77

8-
1. You can use the `Bash script <https://github.com/mattermost/docs/tree/master/source/scripts/generate-certificates>`__ from the ``mattermost/docs`` repository on GitHub, or any other suitable method.
8+
1. You can use the `Bash script <https://github.com/mattermost/docs/tree/master/source/scripts/generate-certificates>`_ from the ``mattermost/docs`` repository on GitHub, or any other suitable method. See the :doc:`generate self-signed certificates </scripts/generate-certificates/gencert>` documentation for details on generating a self-signed x509v3 certificate for use with multiple URLs / IPs.
99
2. Save the two files that are generated. They are the private key and the public key. In the System Console, they are referred to as the **Service Provider Private Key** and the **Service Provider Public Certificate** respectively.

Diff for: source/onboard/sso-saml.rst

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Mattermost officially supports Okta, OneLogin, and Microsoft ADFS as the identit
2828
:titlesonly:
2929

3030
Okta SAML Configuration <sso-saml-okta>
31+
Generate self-signed certificates </scripts/generate-certificates/gencert>
3132
OneLogin SAML Configuration <sso-saml-onelogin.rst>
3233
Microsoft ADFS SAML Configuration for Windows Server 2012 <sso-saml-adfs>
3334
Microsoft ADFS SAML Configuration for Windows Server 2016 <sso-saml-adfs-msws2016>

Diff for: source/scale/performance-monitoring-metrics.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ Login and session metrics
7777

7878
.. note::
7979
From Mattermost version v9.9, this value includes any potentially unauthenticated connections. Furthermore, this metric comes with an ``origin_client`` label that can be used to see the distribution of connections from different client types (i.e. web, mobile, and desktop).
80-
- ``mattermost_login_logins_fail_total``: The total number of failed logins.
81-
- ``mattermost_login_logins_total``: The total number of successful logins.
80+
81+
- ``mattermost_login_logins_fail_total``: The total number of failed logins.
82+
- ``mattermost_login_logins_total``: The total number of successful logins.
8283

8384
Mattermost channels metrics
8485
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Diff for: source/scripts/generate-certificates/gencert.renamed renamed to source/scripts/generate-certificates/gencert.md

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
---
2-
nosearch: true
3-
---
4-
5-
<!---This documentation page is intentionally missing from the LHS. You can safely ignore related build warnings.--->
6-
71
# gencert.sh for Mattermost
82

93
Generate a self-signed x509v3 certificate for use with multiple URLs / IPs.
@@ -21,6 +15,7 @@ CRT_CN="client.com" CRT_SAN="DNS.1:www.client.com,DNS.2:admin.client.com,IP.1:19
2115
You may change the `CRT_CN` and `CRT_SAN` values of the above command based on your needs.
2216

2317
Additionally you may use any of the following environment variables :
18+
- `CRT_FILENAME`: the name of the cert and key files i.e. `<CRT_FILENAME>.key` and `<CRT_FILENAME>.crt`
2419
- `CRT_C` : Country value
2520
- `CRT_L` : Locality value
2621
- `CRT_O` : Organization value
@@ -31,8 +26,8 @@ Additionally you may use any of the following environment variables :
3126
### Result
3227

3328
The command will generate two files:
34-
- pkcs#8 private key : `mattermost-x509.key`
35-
- x509v3 certificate : `mattermost-x509.crt`
29+
- pkcs#8 private key : `mattermost-x509.key` (unless you set `CRT_FILENAME`)
30+
- x509v3 certificate : `mattermost-x509.crt` (unless you set `CRT_FILENAME`)
3631

3732
You can confirm the certificate content by using the following standard `x509` command:
3833

Diff for: source/scripts/generate-certificates/gencert.sh

+39-13
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,47 @@
22

33
umask 007
44

5-
certname="${CRT_FILENAME:-"mattermost-x509"}"
5+
FILE_NAME="${CRT_FILENAME:-"mattermost-x509"}"
6+
CERT="${FILE_NAME}.crt"
7+
KEY="${FILE_NAME}.key"
8+
CSR="${FILE_NAME}.csr"
9+
10+
# generate key
11+
openssl genrsa -out $KEY 4096
12+
13+
if [ $? -ne 0 ]; then
14+
echo "Error generating key"
15+
exit
16+
fi
17+
18+
# generate certificate signing request
19+
openssl req \
20+
-new \
21+
-key $KEY \
22+
-out $CSR \
23+
-subj "/C=${CRT_C:-"US"}/L=${CRT_L:-"Palo Alto"}/O=${CRT_O:-"Mattermost"}/OU=${CRT_OU:-"DevOps"}/CN=${CRT_CN:-"base.example.com"}"
24+
25+
if [ $? -ne 0 ]; then
26+
echo "Error generating certificate signing request (csr)"
27+
exit
28+
fi
29+
30+
# generate self-signed certificate
631
openssl x509 \
7-
-in <(
8-
openssl req \
9-
-days 3650 \
10-
-newkey rsa:4096 \
11-
-nodes \
12-
-keyout "${certname}.key" \
13-
-subj "/C=${CRT_C:-"US"}/L=${CRT_L:-"Palo Alto"}/O=${CRT_O:-"Mattermost"}/OU=${CRT_OU:-"DevOps"}/CN=${CRT_CN:-"base.example.com"}"
14-
) \
1532
-req \
16-
-signkey "${certname}.key" \
17-
-sha256 \
1833
-days 3650 \
19-
-out "${certname}.crt" \
34+
-in $CSR \
35+
-signkey $KEY \
36+
-sha256 \
37+
-out $CERT \
2038
-extfile <(echo -e "basicConstraints=critical,CA:true,pathlen:0\nsubjectAltName=${CRT_SAN:-"DNS.1:logs.example.com,DNS.2:metrics.example.com,IP.1:192.168.0.1,IP.2:127.0.0.1"}")
2139

22-
chmod 600 ${certname}.crt
40+
if [ $? -ne 0 ]; then
41+
echo "Error generating self-signed certificate"
42+
exit
43+
fi
44+
45+
rm $CSR
46+
chmod 600 $CERT
47+
48+
echo -e "\nSuccess! $KEY and $CERT generated."

0 commit comments

Comments
 (0)