Skip to content

Commit ea9b759

Browse files
committed
Enable token prefix masking
If the features passed by the Gitlab server indicate that there are token prefixes that should be masked, this adds those prefixes to the Masker. This is fully transparent to users of this crate; the correct thing will happen provided they correctly identify which artifacts they believe should be masked. The trace will always be masked correctly.
1 parent efbbf3d commit ea9b759

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

gitlab-runner/src/run.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytes::Bytes;
2-
use masker::Masker;
2+
use masker::{Masker, MatchData};
33
use std::future::Future;
44
use std::path::PathBuf;
55
use std::sync::Arc;
@@ -17,6 +17,8 @@ use crate::CancellableJobHandler;
1717
use crate::{JobResult, Phase};
1818

1919
const GITLAB_MASK: &str = "[MASKED]";
20+
const GITLAB_TOKEN_SUFFIX_CHARS: &str =
21+
"-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz=";
2022

2123
async fn run<F, J, Ret>(
2224
job: Job,
@@ -195,7 +197,22 @@ impl Run {
195197
.filter(|(_, v)| v.masked)
196198
.map(|(_, v)| v.value.as_str())
197199
.collect::<Vec<_>>();
198-
let masker = Masker::new(&masked_variables, GITLAB_MASK);
200+
let prefixes = self
201+
.response
202+
.features
203+
.iter()
204+
.flat_map(|x| x.token_mask_prefixes.iter())
205+
// This matches the behaviour of the gitlab runner, which
206+
// explicitly supports a maximum of 10 prefixes.
207+
.take(10)
208+
.map(|p| MatchData {
209+
prefix: p.trim().as_bytes(),
210+
suffix: GITLAB_TOKEN_SUFFIX_CHARS.as_bytes(),
211+
mask_prefix: false,
212+
})
213+
.collect::<Vec<_>>();
214+
215+
let masker = Masker::new_with_match_data(&masked_variables, &prefixes, GITLAB_MASK);
199216

200217
let job = Job::new(
201218
self.client.clone(),

0 commit comments

Comments
 (0)