Skip to content

PAPP-36780 cert based auth#58

Open
NiemySpiewak-splunk wants to merge 4 commits intomsankowska/PSAAS-24763-porting_HTTP_to_SDKfrom
msankowska/PAPP-36780-cert-based-auth
Open

PAPP-36780 cert based auth#58
NiemySpiewak-splunk wants to merge 4 commits intomsankowska/PSAAS-24763-porting_HTTP_to_SDKfrom
msankowska/PAPP-36780-cert-based-auth

Conversation

@NiemySpiewak-splunk
Copy link
Copy Markdown

Features

List any features you're adding to this app (e.g. new actions, parameters, auth methods, etc.)

  • Added support for client certificate authentication in the HTTP

Manual Documentation

Have you made any changes that should be documented in manual_readme_content.md? NO

The following changes require documentation in manual_readme_content.md:

  • New, updated, or removed REST handlers
  • New, updated, or removed authentication methods, especially complex methods like OAuth
  • Compatibility considerations with respect to deployment types (e.g. actions that cannot be run on cloud or an automation broker)
  • I have verified that manual documentation has been updated where appropriate

Comment on lines +137 to +138
cert_bytes = base64.b64decode(asset.public_cert)
key_bytes = base64.b64decode(asset.private_key)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd move those 2 lines outside of try, at this point we don't have anything to delete

):
logger.warning(
"Request failed with 401, token might be expired. Forcing a refresh."
cert_manager = temp_cert_files(asset) if (asset.client_cert and asset.client_key) else nullcontext()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why are we checking for client_key and client_cert when temp_cert_files uses different params of an Asset?

Btw does the temp_cert_files need the whole asset? I think we might be good with just cert params ;)

also it would be cleaener to be able to use it just like with temp_cert_files(cert ,key) as cert_param:
...

Comment on lines +57 to +66
with cert_manager as cert_param:
retries = 1
response = None

while retries >= 0:
auth_method = get_auth_method(asset, soar)
auth_object, final_headers = auth_method.create_auth(parsed_headers)

try:
response = requests.request(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we have kind of scope creep here, block inside a block inside another block.
Any ideas how we can get around that?

break

except requests.exceptions.RequestException as e:
if isinstance(auth_method, OAuth) and e.response and e.response.status_code == 401 and retries > 0:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like an old version of the base branch. This should be

if isinstance(auth_method, OAuth) and retries > 0: see https://github.com/splunk-soar-connectors/http_app/blob/msankowska/PSAAS-24763-porting_HTTP_to_SDK/src/request_maker.py#L82

you probably need to merge the base branch with this branch and fix any merge conflicts

@tapishj-splunk tapishj-splunk force-pushed the msankowska/PSAAS-24763-porting_HTTP_to_SDK branch from 93b37f3 to 59500e8 Compare September 23, 2025 23:11
"Request failed with 401, token might be expired. Forcing a refresh."
body = UnicodeDammit(body).unicode_markup.encode("utf-8") if isinstance(body, str) else body

with temp_cert_files(asset.public_cert, asset.private_key) as cert_param:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems like somewhat of an anti-pattern. It implies that we can have token based auth and then get_auth_method can still return a different type of auth. We're implementing standalone cert based auth. Let's change this logic by creating a CertBasedAuth class that inherits Authorization in auth.py, then have get_auth_method return CertBasedAuth is asset.public_cert and asset.private_key are present.

I also think we shouldn't surround the entire function with a context manager when it's not going to be used most of the time. Lets do something like this

Suggested change
with temp_cert_files(asset.public_cert, asset.private_key) as cert_param:
auth_method = get_auth_method(asset, soar)
if isinstance(auth_method, CertificateAuth):
return _execute_certificate_request(auth_method, full_url, method, body, verify, parsed_headers, output, asset, soar)
else:
return _execute_standard_request(auth_method, full_url, method, body, verify, parsed_headers, output, asset, soar)

_execute_certificate_request would then make certificate based requests and _execute_standard_request would be responsible for everything else

Comment on lines +135 to +136
cert_bytes = base64.b64decode(asset.public_cert)
key_bytes = base64.b64decode(asset.private_key)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't these use cert_b64 and key_b64 respectively

@tapishj-splunk tapishj-splunk force-pushed the msankowska/PSAAS-24763-porting_HTTP_to_SDK branch from a7a9822 to ee75fbf Compare October 13, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants