Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for elevated permissions with automatic login #482

Merged
merged 50 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e9f18ac
okta: add dsso authentication
gord5500 Sep 17, 2024
a16a9e9
add cancellation token to newpageasync
gord5500 Sep 17, 2024
6fc7baa
tweak warning messages
gord5500 Sep 17, 2024
73d0cdd
Update src/D2L.Bmx/OktaAuthenticator.cs
gord5500 Sep 17, 2024
c2f13bd
var name tweak
gord5500 Sep 17, 2024
19fa544
tweak warning message for non matching user
gord5500 Sep 17, 2024
4f177b7
mend
gord5500 Sep 17, 2024
aedb835
change reload signin page
gord5500 Sep 17, 2024
c14de8e
add passwordless option that defaults to false
gord5500 Sep 17, 2024
77a91c4
mend
gord5500 Sep 17, 2024
1b8cfd2
tweak warning message
gord5500 Sep 17, 2024
1a8ba2e
set browser as headless based on bmx_debug env variable
gord5500 Sep 17, 2024
b526dbe
readd path check
gord5500 Sep 17, 2024
d502f1d
default browser to edge for windows
gord5500 Sep 17, 2024
28b320a
headless is always true regardless of bmx_debug
gord5500 Sep 17, 2024
7633b0f
make no-sandbox option scarier
gord5500 Sep 17, 2024
185b8ff
abort if not on vpn
gord5500 Sep 17, 2024
d9fe294
normalize okta org and check users route
gord5500 Sep 17, 2024
0080063
remove passwordless flag
gord5500 Sep 17, 2024
ac51994
mend
gord5500 Sep 17, 2024
ff3f8e1
adjust parameter name for experimental
gord5500 Sep 17, 2024
551f6cf
rename okta session function
gord5500 Sep 17, 2024
64f5efb
redo org check
gord5500 Sep 18, 2024
40171e4
Update src/D2L.Bmx/Browser.cs
gord5500 Sep 18, 2024
a2f903a
nits
gord5500 Sep 18, 2024
88f7517
more nits
gord5500 Sep 19, 2024
91d52b6
readd user email strip check
gord5500 Sep 19, 2024
684f1bd
mend
gord5500 Sep 19, 2024
81a3714
mend
gord5500 Sep 19, 2024
d48c7db
deal in uris instread of string for orgs
gord5500 Sep 19, 2024
7a68852
remove OktaHomeResponse model
gord5500 Sep 19, 2024
6dba5c1
rename to orgUrl
gord5500 Sep 19, 2024
f46d800
dont mention sso
gord5500 Sep 20, 2024
fa1fd6d
simplify login name check
gord5500 Sep 20, 2024
fc17c78
Update src/D2L.Bmx/ParameterDescriptions.cs
gord5500 Sep 24, 2024
e479bc8
Update src/D2L.Bmx/OktaAuthenticator.cs
gord5500 Sep 24, 2024
d87d349
Update src/D2L.Bmx/OktaAuthenticator.cs
gord5500 Sep 24, 2024
754699e
Update src/D2L.Bmx/OktaAuthenticator.cs
gord5500 Sep 24, 2024
1054c06
Update src/D2L.Bmx/OktaAuthenticator.cs
gord5500 Sep 24, 2024
7ec3833
don't pass the client factory
gord5500 Sep 24, 2024
de1e41f
check elevated permissions on experimental flag
gord5500 Sep 24, 2024
96a9e7d
scarier message
gord5500 Sep 24, 2024
96177a7
fix libc call
ArckosLiam Sep 24, 2024
5b05ca9
format
gord5500 Sep 24, 2024
afef184
wording
gord5500 Sep 24, 2024
c956f2a
don't kill on bad setup
gord5500 Sep 24, 2024
9d717e8
mend
gord5500 Sep 24, 2024
e47e88b
mend
gord5500 Sep 24, 2024
7063367
Merge branch 'main' into check_for_elevated_permission
gord5500 Sep 24, 2024
521a53f
reword the warning message
gord5500 Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/D2L.Bmx/OktaAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,24 @@ private bool TryAuthenticateFromCache(
Uri orgUrl,
string user,
bool nonInteractive,
bool experimentalBypassBrowserSecurity
bool bypassBrowserSecurity
) {
await using IBrowser? browser = await Browser.LaunchBrowserAsync( experimentalBypassBrowserSecurity );

bool hasElevatedPermissions = UserPrivileges.HasElevatedPermissions();
if( hasElevatedPermissions && !bypassBrowserSecurity ) {
consoleWriter.WriteWarning( $"""
BMX is being run with elevated privileges and is unable to automatically sign in to Okta.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in scope, but - some warnings messages are prefixed with "WARNING:" while others are not.
Would be nice to be consistent on this.
I lean towards no prefix, because we already use a different colour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yea you're right. I started with including the prefix since they were in the bmx config provider class but have been inconsistent. I see we use WriteWarning in other places though without it. I think I'll remove the prefix for this class

If you want to automatically sign in, and aren't concerned with the security of {orgUrl.Host},
consider using '--experimental-bypass-browser-security' flag.
"""
);
return null;
} else if( !hasElevatedPermissions && bypassBrowserSecurity ) {
// We want to avoid providing '--no-sandbox' to chromium unless absolutely neccessary.
bypassBrowserSecurity = false;
}

await using IBrowser? browser = await Browser.LaunchBrowserAsync( bypassBrowserSecurity );
if( browser is null ) {
return null;
}
Expand Down Expand Up @@ -178,7 +193,7 @@ async Task GetSessionCookieAsync() {
await page.GoToAsync( orgUrl.AbsoluteUri ).WaitAsync( cancellationTokenSource.Token );
} else {
consoleWriter.WriteWarning(
"WARNING: Failed to authenticate with Okta when trying to automatically sign in" );
"Failed to authenticate with Okta when trying to automatically sign in" );
sessionIdTcs.SetResult( null );
}
return;
Expand All @@ -191,21 +206,21 @@ async Task GetSessionCookieAsync() {
}
} catch( TaskCanceledException ) {
consoleWriter.WriteWarning( $"""
WARNING: Timed out when trying to automatically sign in to Okta. Check if the org '{orgUrl}' is correct.
Timed out when trying to automatically sign in to Okta. Check if the org '{orgUrl}' is correct.
If you have to run BMX with elevated privileges, and aren't concerned with the security of {orgUrl.Host},
consider running the command again with the '--experimental-bypass-browser-security' flag.
"""
);
} catch( TargetClosedException ) {
consoleWriter.WriteWarning( """
WARNING: Failed to automatically sign in to Okta as BMX is likely being run with elevated privileges.
Failed to automatically sign in to Okta as BMX is likely being run with elevated privileges.
If you have to run BMX with elevated privileges, and aren't concerned with the security of {orgUrl.Host},
consider running the command again with the '--experimental-bypass-browser-security' flag.
"""
);
} catch( Exception ) {
consoleWriter.WriteWarning(
"WARNING: Unknown error occurred while trying to automatically sign in with Okta." );
"Unknown error occurred while trying to automatically sign in with Okta." );
}

if( sessionId is null ) {
Expand All @@ -218,7 +233,7 @@ consider running the command again with the '--experimental-bypass-browser-secur
string providedLogin = user.Split( "@" )[0];
if( !sessionLogin.Equals( providedLogin, StringComparison.OrdinalIgnoreCase ) ) {
consoleWriter.WriteWarning(
"WARNING: Could not automatically sign in to Okta as provided Okta user "
"Could not automatically sign in to Okta as provided Okta user "
+ $"'{sessionLogin}' does not match user '{providedLogin}'." );
return null;
}
Expand Down
20 changes: 20 additions & 0 deletions src/D2L.Bmx/UserPrivilieges.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Runtime.InteropServices;
using System.Security.Principal;

namespace D2L.Bmx;

internal static partial class UserPrivileges {

[LibraryImport( "libc", EntryPoint = "geteuid" )]
internal static partial uint GetPosixEuid();

internal static bool HasElevatedPermissions() {
bool isElevated = false;
if( OperatingSystem.IsWindows() ) {
isElevated = new WindowsPrincipal( WindowsIdentity.GetCurrent() ).IsInRole( WindowsBuiltInRole.Administrator );
} else if( OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() ) {
isElevated = GetPosixEuid() == 0;
}
return isElevated;
}
}
Loading