Skip to content

Commit 5b46a18

Browse files
authored
Fix: Step-up checks too narrow (#150)
1 parent 47cf2be commit 5b46a18

File tree

10 files changed

+37
-17
lines changed

10 files changed

+37
-17
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Tokendito
2+
13
<p align="center">
24
<img src="https://raw-githubusercontent-com-gh.computerqwq.top/dowjones/tokendito/main/docs/tokendito.png"/>
35
</p>
@@ -26,11 +28,19 @@ tokens into your local `~/.aws/credentials` file.
2628

2729
See [Releases](https://github.com/dowjones/tokendito/releases) for a detailed Changelog.
2830

31+
### Tokendito 2.4.0
32+
33+
Version 2.4.0 of Tokendito introduces the following new features:
34+
35+
- Add support for Okta question MFA.
36+
- Many bug fixes and contributions.
37+
2938
### Tokendito 2.3.0
3039

3140
Version 2.3.0 of Tokendito introduces the following new features:
3241

3342
- Basic OIE support while forcing Classic mode.
43+
- Support for saving the Device Token ID for later reuse.
3444
- Misc bug fixes
3545

3646
Note: This feature currently works with locally enabled OIE organizations, but it does not for Organizations with chained Authentication in mixed OIE/Classic environments.

docs/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ tokendito --profile engineer
7474
usage: tokendito [-h] [--version] [--configure] [--username OKTA_USERNAME] [--password OKTA_PASSWORD] [--profile USER_CONFIG_PROFILE] [--config-file USER_CONFIG_FILE]
7575
[--loglevel {DEBUG,INFO,WARN,ERROR}] [--log-output-file USER_LOG_OUTPUT_FILE] [--aws-config-file AWS_CONFIG_FILE] [--aws-output AWS_OUTPUT]
7676
[--aws-profile AWS_PROFILE] [--aws-region AWS_REGION] [--aws-role-arn AWS_ROLE_ARN] [--aws-shared-credentials-file AWS_SHARED_CREDENTIALS_FILE]
77-
[--okta-org OKTA_ORG | --okta-tile OKTA_TILE] [--okta-mfa OKTA_MFA] [--okta-mfa-response OKTA_MFA_RESPONSE] [--use-device-token] [--quiet]
77+
[--okta-org OKTA_ORG | --okta-tile OKTA_TILE] [--okta-client-id OKTA_CLIENT_ID] [--okta-mfa OKTA_MFA] [--okta-mfa-response OKTA_MFA_RESPONSE]
78+
[--use-device-token] [--quiet]
7879
7980
Gets an STS token to use with the AWS CLI and SDK.
8081
@@ -111,9 +112,9 @@ options:
111112
Okta tile URL to use.
112113
--okta-client-id OKTA_CLIENT_ID
113114
For OIE enabled Orgs this sets the Okta client ID to replace the value found by tokendito. It is used in the authorize code flow.
114-
--okta-mfa OKTA_MFA Sets the MFA method
115+
--okta-mfa OKTA_MFA Sets the MFA method. You can also use the TOKENDITO_OKTA_MFA environment variable.
115116
--okta-mfa-response OKTA_MFA_RESPONSE
116-
Sets the MFA response to a challenge
117+
Sets the MFA response to a challenge. You can also use the TOKENDITO_OKTA_MFA_RESPONSE environment variable.
117118
--use-device-token Use device token across sessions
118119
--quiet Suppress output
119120
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exclude_lines = [
77
"break",
88
"except KeyboardInterrupt:",
99
"if __name__ == .__main__.:",
10-
"if __package__ is None:",
10+
"if not __package__:",
1111
"logger.debug",
1212
"pragma: no cover",
1313
"print..Invalid input, try again...",

tokendito/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# vim: set filetype=python ts=4 sw=4
22
# -*- coding: utf-8 -*-
33
"""Tokendito module initialization."""
4-
__version__ = "2.3.3"
4+
__version__ = "2.4.0"
55
__title__ = "tokendito"
66
__description__ = "Get AWS STS tokens from Okta SSO"
77
__long_description_content_type__ = "text/markdown"

tokendito/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def main(args=None): # needed for console script
99
"""Packge entry point."""
10-
if __package__ is None:
10+
if not __package__:
1111
import os.path
1212

1313
path = os.path.dirname(os.path.dirname(__file__))

tokendito/aws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def authenticate_to_roles(config, urls):
7272
saml_xml = okta.extract_saml_response(saml_response_string)
7373
if not saml_xml:
7474
state_token = okta.extract_state_token(saml_response_string)
75-
if "Extra Verification" in saml_response_string and state_token:
75+
if state_token:
7676
logger.info(f"Step-Up authentication required for {url}.")
7777
if okta.step_up_authenticate(config, state_token):
7878
return authenticate_to_roles(config, urls)

tokendito/http_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def get(self, url, params=None, headers=None, allow_redirects=True):
8181

8282
def post(self, url, data=None, json=None, headers=None, params=None, return_json=False):
8383
"""Perform a POST request."""
84+
response = None
8485
logger.debug(f"POST to {url}")
8586
try:
8687
response = self.session.post(url, data=data, json=json, params=params, headers=headers)
@@ -95,6 +96,11 @@ def post(self, url, data=None, json=None, headers=None, params=None, return_json
9596
return response
9697
except requests.RequestException as e:
9798
logger.error(f"Error during POST request to {url}. Error: {e}")
99+
if response:
100+
logger.debug(f"Response Headers: {response.headers}")
101+
logger.debug(f"Response Text: {response.text}")
102+
else:
103+
logger.debug("No response received")
98104
sys.exit(1)
99105
except Exception as err:
100106
logger.error(f"The post request to {url} failed with {err}")

tokendito/okta.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ def get_saml_request(auth_properties):
129129
response = HTTP_client.get(url, headers=headers)
130130

131131
# Extract the required parameters from the SAML request.
132+
post_url = extract_form_post_url(response.text)
133+
base_url = user.get_base_url(post_url)
132134
saml_request = {
133-
"base_url": user.get_base_url(extract_form_post_url(response.text)),
134-
"post_url": extract_form_post_url(response.text),
135+
"base_url": base_url,
136+
"post_url": post_url,
135137
"relay_state": extract_saml_relaystate(response.text),
136138
"request": extract_saml_request(response.text, raw=True),
137139
}
@@ -263,7 +265,6 @@ def send_saml_response(config, saml_response):
263265

264266
# Get the 'sid' value from the reponse cookies.
265267
sid = response.cookies.get("sid", None)
266-
logger.debug(f"New sid is {sid}")
267268

268269
# If 'sid' is present, mask its value for logging purposes.
269270
if sid:
@@ -564,6 +565,12 @@ def authorize_request(oauth2_config, oauth2_session_data):
564565
params=payload,
565566
)
566567

568+
idx = HTTP_client.session.cookies.get("idx", None)
569+
if idx:
570+
user.add_sensitive_value_to_be_masked(idx)
571+
else:
572+
logger.debug("We did not find an 'idx' entry in the cookies.")
573+
567574
authorize_code = get_authorize_code(response, session_token)
568575
return authorize_code
569576

@@ -699,6 +706,7 @@ def idp_authenticate(config):
699706
logger.error("Okta auth failed: unknown type.")
700707
sys.exit(1)
701708

709+
# Possible recursion ahead. The exit condition should be the first if statement.
702710
if local_authentication_enabled(auth_properties):
703711
session_token = local_authenticate(config)
704712
# authentication sends us a token

tokendito/tokendito.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def main(args=None): # needed for console script
99
"""Packge entry point."""
10-
if __package__ is None:
10+
if not __package__:
1111
import os.path
1212

1313
path = os.path.dirname(os.path.dirname(__file__))

tokendito/user.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ def cmd_interface(args):
7979

8080
# get authentication and authorization cookies from okta
8181
okta.access_control(config)
82-
logger.debug(
83-
f"""
84-
about to call discover_tile
85-
we have client cookies: {HTTP_client.session.cookies}
86-
"""
87-
)
82+
8883
if config.okta["tile"]:
8984
tile_label = ""
9085
config.okta["tile"] = (config.okta["tile"], tile_label)

0 commit comments

Comments
 (0)