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

certificatePath and certificateKeyPath should be read as binary #1462

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

williambernardet
Copy link
Contributor

With latest version of the agent extension, I've tried to leverage the new certificatePath and certificateKeyPath to read existing certificate, and the extension fails in the following way. As we write them back with 'wb', we need to load them as bytes.

2021/11/16 17:45:24 ERROR:Install failed with error: a bytes-like object is required, not 'str'
2021/11/16 17:45:24 ERROR:Stacktrace: Traceback (most recent call last):
2021/11/16 17:45:24 ERROR: File "./agent.py", line 189, in main
2021/11/16 17:45:24 ERROR: exit_code, output = operationsoperation
2021/11/16 17:45:24 ERROR: File "./agent.py", line 452, in install
2021/11/16 17:45:24 ERROR: fh.write(MONITORING_GCS_CERT_CERTFILE)
2021/11/16 17:45:24 ERROR:TypeError: a bytes-like object is required, not 'str'
2021/11/16 17:45:24 ERROR:
2021/11/16 17:45:24 ERROR:[Microsoft.Azure.Monitor.AzureMonitorLinuxAgent-1.14.5] Install failed with error: a bytes-lik
e object is required, not 'str'
2021/11/16 17:45:24 ERROR:Stacktrace: Traceback (most recent call last):
2021/11/16 17:45:24 ERROR: File "./agent.py", line 189, in main
2021/11/16 17:45:24 ERROR: exit_code, output = operationsoperation
2021/11/16 17:45:24 ERROR: File "./agent.py", line 452, in install
2021/11/16 17:45:24 ERROR: fh.write(MONITORING_GCS_CERT_CERTFILE)
2021/11/16 17:45:24 ERROR:TypeError: a bytes-like object is required, not 'str'
2021/11/16 17:45:24 ERROR:
2021/11/16 17:45:24 [Microsoft.Azure.Monitor.AzureMonitorLinuxAgent-1.14.5] Install,failed,1,Install failed with error:
a bytes-like object is required, not 'str'
2021/11/16 17:45:24 Stacktrace: Traceback (most recent call last):
2021/11/16 17:45:24 File "./agent.py", line 189, in main
2021/11/16 17:45:24 exit_code, output = operationsoperation
2021/11/16 17:45:24 File "./agent.py", line 452, in install
2021/11/16 17:45:24 fh.write(MONITORING_GCS_CERT_CERTFILE)
2021/11/16 17:45:24 TypeError: a bytes-like object is required, not 'str'

@williambernardet williambernardet requested a review from a team as a code owner November 16, 2021 18:32
@@ -367,7 +367,7 @@ def install():

if "certificatePath" in protected_settings:
try:
with open(protected_settings.get("certificatePath"), 'r') as f:
with open(protected_settings.get("certificatePath"), 'rb') as f:

Choose a reason for hiding this comment

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

This code changes the read path, however the error message provided in the PR points to it attempting to write, which happens here:

fh.write(MONITORING_GCS_CERT_CERTFILE)

Choose a reason for hiding this comment

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

Ah, I see, it reads it and then writes it. Nevermind on this comment.

@hestolz
Copy link
Contributor

hestolz commented Dec 10, 2021

@williambernardet please test this on py2 and py3 both

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