Skip to content

Commit 88fea75

Browse files
authored
add option to load a custom CA cert (#353)
* add option to load a custom CA cert * rename * removed debug log
1 parent b820c18 commit 88fea75

File tree

6 files changed

+194
-14
lines changed

6 files changed

+194
-14
lines changed

README.md

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The default functionality of Gitlab is limited at the project level. This can be
1414
of
1515
projects, potentially resulting in undetected failed pipelines.
1616

17-
## 👉 [Demo (main branch)](https://gitlab-ci-dashboard.larscom.nl)
17+
## 👉 [Demo](https://gitlab-ci-dashboard.larscom.nl)
1818

1919
<br />
2020

@@ -66,13 +66,22 @@ projects, potentially resulting in undetected failed pipelines.
6666
2. Run docker with the required environment variables (GITLAB_BASE_URL, GITLAB_API_TOKEN)
6767

6868
```bash
69-
docker run -p 8080:8080 -e GITLAB_BASE_URL=https://gitlab.com -e GITLAB_API_TOKEN=my_token larscom/gitlab-ci-dashboard:latest
69+
docker run \
70+
-p 8080:8080 \
71+
-e GITLAB_BASE_URL=https://gitlab.com \
72+
-e GITLAB_API_TOKEN=my_token \
73+
larscom/gitlab-ci-dashboard:latest
7074
```
7175

7276
Or you can run it with a TOML configration file
7377

7478
```bash
75-
docker run -p 8080:8080 -v $(pwd)/config.toml:/app/config.toml larscom/gitlab-ci-dashboard:latest
79+
docker run \
80+
-p 8080:8080 \
81+
-e GITLAB_BASE_URL=https://gitlab.com \
82+
-e GITLAB_API_TOKEN=my_token \
83+
-v ./config.toml:/app/config.toml \
84+
larscom/gitlab-ci-dashboard:latest
7685
```
7786

7887
3. Dashboard should be available at: http://localhost:8080/ showing (by default) all available groups and their
@@ -103,13 +112,39 @@ A TOML file takes precedence over environment variables, except for the `RUST_LO
103112

104113
> An example TOML file can be found inside the `./api` folder.
105114
106-
Mount the `config.toml` inside the container.
115+
Mount the `config.toml` inside the container (`/app/config.toml`)
107116

108117
```bash
109-
docker run -p 8080:8080 -v $(pwd)/config.toml:/app/config.toml larscom/gitlab-ci-dashboard:latest
118+
docker run \
119+
-p 8080:8080 \
120+
-e GITLAB_BASE_URL=https://gitlab.com \
121+
-e GITLAB_API_TOKEN=my_token \
122+
-v ./config.toml:/app/config.toml \
123+
larscom/gitlab-ci-dashboard:latest
110124
```
111125

112-
### Environment variables
126+
## 📜 Custom CA certificate
127+
If you are running a gitlab instance that is using a TLS certificate signed with a private CA you are able to provide that CA as mount (PEM encoded)
128+
129+
This is needed when the dashboard backend is unable to make a connection to the gitlab API over HTTPS.
130+
131+
Mount the `ca.crt` inside the container (`/app/certs/ca.crt`)
132+
133+
```bash
134+
docker run \
135+
-p 8080:8080 \
136+
-e GITLAB_BASE_URL=https://gitlab.com \
137+
-e GITLAB_API_TOKEN=my_token \
138+
-v ./ca.crt:/app/certs/ca.crt \
139+
larscom/gitlab-ci-dashboard:latest
140+
```
141+
142+
### Troubleshooting
143+
If you are still unable to connect with a custom CA cert, be sure that the gitlab server certificate contains a valid SAN (Subject Alternative Name)
144+
145+
If there is a mismatch the HTTP client is still unable to make a proper connection.
146+
147+
## 🌍 Environment variables
113148

114149
| Variable | Type | Description | Required | Default |
115150
|-----------------------------------|--------|------------------------------------------------------------------------------------------------------------------------------------|----------|--------------|

api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.env
22
config.toml
3+
certs/

api/Cargo.lock

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dotenv = "0.15.0"
1616
env_logger = "0.11.8"
1717
log = "0.4.28"
1818
moka = { version = "0.12.11", features = ["future"] }
19-
reqwest = { version = "0.12.24", features = ["json"] }
19+
reqwest = { version = "0.12.24", features = ["json", "rustls-tls"] }
2020
tokio = { version = "1.48.0", features = ["sync"] }
2121
async-trait = "0.1.89"
2222
futures = "0.3.31"

api/src/gitlab.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use reqwest::{Client, Url};
1111
use serde::de::DeserializeOwned;
1212
use serde_json::Value;
1313
use std::collections::HashMap;
14+
use std::fs;
1415
use tokio::sync::mpsc;
1516

1617
#[async_trait]
@@ -79,14 +80,29 @@ struct Page<T: DeserializeOwned> {
7980
}
8081

8182
impl GitlabClient {
83+
fn get_ca_cert() -> Option<reqwest::Certificate> {
84+
match fs::read("./certs/ca.crt") {
85+
Ok(cert) => {
86+
let ca = String::from_utf8_lossy(&cert);
87+
log::debug!("Found custom CA cert:\n{ca}");
88+
Some(reqwest::Certificate::from_pem(&cert).expect("invalid cert"))
89+
}
90+
Err(_) => None,
91+
}
92+
}
93+
8294
pub fn new(gitlab_url: &str, gitlab_token: &str) -> Self {
83-
let http_client = Client::builder()
84-
.default_headers(create_http_headers(gitlab_token))
85-
.build()
86-
.expect("http client to be build");
95+
let mut client_builder = Client::builder()
96+
.use_rustls_tls()
97+
.default_headers(create_http_headers(gitlab_token));
98+
99+
if let Some(ca) = Self::get_ca_cert() {
100+
client_builder = client_builder.add_root_certificate(ca);
101+
}
102+
87103
Self {
88104
base_url: format!("{gitlab_url}/api/v4"),
89-
http_client,
105+
http_client: client_builder.build().expect("invalid client"),
90106
}
91107
}
92108
}

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ services:
77
VERSION_ARG: docker
88
env_file:
99
- ./api/.env
10-
# volumes:
11-
# - ./api/config.toml:/app/config.toml
10+
# volumes:
11+
# - ./api/config.toml:/app/config.toml
12+
# - ./api/certs/ca.crt:/app/certs/ca.crt
1213
environment:
1314
- 'TZ=Europe/Amsterdam'
1415
ports:

0 commit comments

Comments
 (0)