Skip to content

Commit 0e6113a

Browse files
mononoke/x509 identity: add OSS parsing of x509 certificates
Summary: This parsing uses the standard "subject name" field of a x509 certificate to create MononokeIdentity. Differential Revision: D22627150 fbshipit-source-id: 94f5c904d533d7d423db1d9ac07f0b553adc7751
1 parent b64f3b8 commit 0e6113a

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

.github/workflows/mononoke-integration_linux.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,3 @@ jobs:
7979
export PYTHONPATH="${dir}${PYTHONPATH:+:${PYTHONPATH}}"
8080
done
8181
python3 eden/mononoke/tests/integration/run_tests_getdeps.py /tmp/build/installed /tmp/build/build/mononoke_integration_test
82-
continue-on-error: true

.github/workflows/mononoke-integration_mac.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ jobs:
7171
pip install click
7272
- name: Check space
7373
run: df -h
74+
- name: Setup tmate session
75+
uses: mxschmitt/action-tmate@v2
7476
- name: Run Monononke integration tests
7577
run: |
7678
for dir in /tmp/build/installed/python-click-*/lib/fb-py-libs/python-click/click; do
7779
export PYTHONPATH="${dir}${PYTHONPATH:+:${PYTHONPATH}}"
7880
done
7981
python3 eden/mononoke/tests/integration/run_tests_getdeps.py /tmp/build/installed /tmp/build/build/mononoke_integration_test
80-
continue-on-error: true

eden/mononoke/permission_checker/src/oss.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@ impl MononokeIdentity {
2222
bail!("Decoding from JSON is not yet implemented for MononokeIdentity")
2323
}
2424

25-
pub fn try_from_x509(_: &X509) -> Result<MononokeIdentitySet> {
26-
bail!("Decoding from x509 is not yet implemented for MononokeIdentity")
25+
pub fn try_from_x509(cert: &X509) -> Result<MononokeIdentitySet> {
26+
let subject_vec: Result<Vec<_>> = cert
27+
.subject_name()
28+
.entries()
29+
.map(|entry| {
30+
Ok(format!(
31+
"{}={}",
32+
entry.object().nid().short_name()?,
33+
entry.data().as_utf8()?
34+
))
35+
})
36+
.collect();
37+
let subject_name = subject_vec?.as_slice().join(",");
38+
39+
let mut idents = MononokeIdentitySet::new();
40+
idents.insert(MononokeIdentity::new("X509_SUBJECT_NAME", subject_name)?);
41+
Ok(idents)
2742
}
2843
}
2944

eden/mononoke/tests/integration/library.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
# Library routines and initial setup for Mononoke-related tests.
88

9+
if [ -f "$TEST_FIXTURES/facebook/fb_library.sh" ]; then
10+
# shellcheck source=fbcode/eden/mononoke/tests/integration/facebook/fb_library.sh
11+
. "$TEST_FIXTURES/facebook/fb_library.sh"
12+
fi
13+
14+
ALLOWED_IDENTITY_TYPE="${FB_ALLOWED_IDENTITY_TYPE:-X509_SUBJECT_NAME}"
15+
ALLOWED_IDENTITY_DATA="${FB_ALLOWED_IDENTITY_DATA:-CN=localhost,O=Mononoke,C=US,ST=CA}"
16+
917
if [[ -n "$DB_SHARD_NAME" ]]; then
1018
MONONOKE_DEFAULT_START_TIMEOUT=60
1119
else
@@ -479,15 +487,13 @@ EOF
479487

480488
echo "{}" > "$TESTTMP/mononoke_tunables.json"
481489

482-
ALLOWED_USERNAME="${ALLOWED_USERNAME:-myusername0}"
483-
484490
cd mononoke-config || exit 1
485491
mkdir -p common
486492
touch common/commitsyncmap.toml
487493
cat > common/common.toml <<CONFIG
488494
[[whitelist_entry]]
489-
identity_type = "USER"
490-
identity_data = "$ALLOWED_USERNAME"
495+
identity_type = "$ALLOWED_IDENTITY_TYPE"
496+
identity_data = "$ALLOWED_IDENTITY_DATA"
491497
CONFIG
492498

493499
echo "# Start new config" > common/storage.toml

eden/mononoke/tests/integration/run_tests_getdeps.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@
5353
pythonpath = env.get("PYTHONPATH")
5454
env["PYTHONPATH"] = eden_scm_packages + (":{}".format(pythonpath) if pythonpath else "")
5555

56-
subprocess.run(
57-
[
58-
sys.executable,
59-
join(repo_root, "eden/mononoke/tests/integration/integration_runner_real.py"),
60-
join(build_dir, "manifest.json"),
61-
]
62-
+ tests,
63-
env=env,
56+
sys.exit(
57+
subprocess.run(
58+
[
59+
sys.executable,
60+
join(repo_root, "eden/mononoke/tests/integration/integration_runner_real.py"),
61+
join(build_dir, "manifest.json"),
62+
]
63+
+ tests,
64+
env=env,
65+
).returncode,
6466
)

0 commit comments

Comments
 (0)