Skip to content

Commit b4c06e8

Browse files
committed
Merge branch 'main' into RUST-1529-no-ff
2 parents 725d373 + be56c79 commit b4c06e8

File tree

6 files changed

+222
-37
lines changed

6 files changed

+222
-37
lines changed

.evergreen/config.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,20 @@ buildvariants:
257257
# Limit the test to only schedule every 14 days to reduce external resource usage.
258258
batchtime: 20160
259259

260-
- name: gssapi-auth
261-
display_name: "GSSAPI Authentication"
260+
- name: gssapi-auth-linux
261+
display_name: "GSSAPI Authentication - Linux"
262262
patchable: true
263263
run_on:
264-
- ubuntu2004-small
264+
- ubuntu2204-small
265+
tasks:
266+
- test-gssapi-auth
267+
268+
- name: gssapi-auth-macos
269+
display_name: "GSSAPI Authentication - macOS"
270+
patchable: true
271+
disable: true
272+
run_on:
273+
- macos-14
265274
tasks:
266275
- test-gssapi-auth
267276

@@ -1389,6 +1398,9 @@ functions:
13891398
AWS_AUTH_TYPE: web-identity
13901399

13911400
"run gssapi auth test":
1401+
- command: ec2.assume_role
1402+
params:
1403+
role_arn: ${aws_test_secrets_role}
13921404
- command: subprocess.exec
13931405
type: test
13941406
params:
@@ -1397,6 +1409,10 @@ functions:
13971409
args:
13981410
- .evergreen/run-gssapi-tests.sh
13991411
include_expansions_in_env:
1412+
- AWS_ACCESS_KEY_ID
1413+
- AWS_SECRET_ACCESS_KEY
1414+
- AWS_SESSION_TOKEN
1415+
- DRIVERS_TOOLS
14001416
- PROJECT_DIRECTORY
14011417

14021418
"run x509 tests":

.evergreen/run-gssapi-tests.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,59 @@ cd ${PROJECT_DIRECTORY}
99
source .evergreen/env.sh
1010
source .evergreen/cargo-test.sh
1111

12+
# Source the drivers/atlas_connect secrets, where GSSAPI test values are held
13+
source "${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh" drivers/atlas_connect
14+
1215
FEATURE_FLAGS+=("gssapi-auth")
1316

1417
set +o errexit
1518

19+
# Create a krb5 config file with relevant
20+
touch krb5.conf
21+
echo "[realms]
22+
$SASL_REALM = {
23+
kdc = $SASL_HOST
24+
admin_server = $SASL_HOST
25+
}
26+
27+
$SASL_REALM_CROSS = {
28+
kdc = $SASL_HOST
29+
admin_server = $SASL_HOST
30+
}
31+
32+
[domain_realm]
33+
.$SASL_DOMAIN = $SASL_REALM
34+
$SASL_DOMAIN = $SASL_REALM
35+
" > krb5.conf
36+
37+
export KRB5_CONFIG=krb5.conf
38+
39+
# Authenticate the user principal in the KDC before running the e2e test
40+
echo "Authenticating $PRINCIPAL"
41+
echo "$SASL_PASS" | kinit -p $PRINCIPAL
42+
klist
43+
44+
# Run end-to-end auth tests for "$PRINCIPAL" user
45+
TEST_OPTIONS+=("--skip with_service_realm_and_host_options")
46+
cargo_test test::auth::gssapi_skip_local
47+
48+
# Unauthenticate
49+
echo "Unauthenticating $PRINCIPAL"
50+
kdestroy
51+
52+
# Authenticate the alternative user principal in the KDC and run other e2e test
53+
echo "Authenticating $PRINCIPAL_CROSS"
54+
echo "$SASL_PASS_CROSS" | kinit -p $PRINCIPAL_CROSS
55+
klist
56+
57+
TEST_OPTIONS=()
58+
cargo_test test::auth::gssapi_skip_local::with_service_realm_and_host_options
59+
60+
# Unauthenticate
61+
echo "Unuthenticating $PRINCIPAL_CROSS"
62+
kdestroy
63+
64+
# Run remaining tests
1665
cargo_test spec::auth
1766
cargo_test uri_options
1867
cargo_test connection_string

Cargo.lock

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

src/client/auth/gssapi.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use cross_krb5::{ClientCtx, InitiateFlags, K5Ctx, PendingClientCtx, Step};
2-
use hickory_resolver::proto::rr::RData;
32

43
use crate::{
54
bson::Bson,
@@ -324,21 +323,24 @@ async fn canonicalize_hostname(
324323
let resolver =
325324
crate::runtime::AsyncResolver::new(resolver_config.map(|c| c.inner.clone())).await?;
326325

327-
match mode {
326+
let hostname = match mode {
328327
CanonicalizeHostName::Forward => {
329328
let lookup_records = resolver.cname_lookup(hostname).await?;
330329

331-
if let Some(first_record) = lookup_records.records().first() {
332-
if let Some(RData::CNAME(cname)) = first_record.data() {
333-
Ok(cname.to_lowercase().to_string())
334-
} else {
335-
Ok(hostname.to_string())
336-
}
330+
if !lookup_records.records().is_empty() {
331+
// As long as there is a record, we can return the original hostname.
332+
// Although the spec says to return the canonical name, this is not
333+
// done by any drivers in practice since the majority of them use
334+
// libraries that do not follow CNAME chains. Also, we do not want to
335+
// use the canonical name since it will likely differ from the input
336+
// name, and the use of the input name is required for the service
337+
// principal to be accepted by the GSSAPI auth flow.
338+
hostname.to_lowercase().to_string()
337339
} else {
338-
Err(Error::authentication_error(
340+
return Err(Error::authentication_error(
339341
GSSAPI_STR,
340342
&format!("No addresses found for hostname: {hostname}"),
341-
))
343+
));
342344
}
343345
}
344346
CanonicalizeHostName::ForwardAndReverse => {
@@ -350,20 +352,27 @@ async fn canonicalize_hostname(
350352
match resolver.reverse_lookup(first_address).await {
351353
Ok(reverse_lookup) => {
352354
if let Some(name) = reverse_lookup.iter().next() {
353-
Ok(name.to_lowercase().to_string())
355+
name.to_lowercase().to_string()
354356
} else {
355-
Ok(hostname.to_lowercase())
357+
hostname.to_lowercase()
356358
}
357359
}
358-
Err(_) => Ok(hostname.to_lowercase()),
360+
Err(_) => hostname.to_lowercase(),
359361
}
360362
} else {
361-
Err(Error::authentication_error(
363+
return Err(Error::authentication_error(
362364
GSSAPI_STR,
363365
&format!("No addresses found for hostname: {hostname}"),
364-
))
366+
));
365367
}
366368
}
367369
CanonicalizeHostName::None => unreachable!(),
368-
}
370+
};
371+
372+
// Sometimes reverse lookup results in a trailing "." since that is the correct
373+
// way to present a FQDN. However, GSSAPI rejects the trailing "." so we remove
374+
// it here manually.
375+
let hostname = hostname.trim_end_matches(".");
376+
377+
Ok(hostname.to_string())
369378
}

src/test/auth.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#[cfg(feature = "aws-auth")]
22
mod aws;
3+
#[cfg(feature = "gssapi-auth")]
4+
#[path = "auth/gssapi.rs"]
5+
mod gssapi_skip_local;
36

47
use serde::Deserialize;
58

0 commit comments

Comments
 (0)