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

debug messages for wca auth #1317

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

debug messages for wca auth #1317

wants to merge 2 commits into from

Conversation

jameswnl
Copy link
Contributor

@jameswnl jameswnl commented Sep 20, 2024

https://issues.redhat.com/browse/AAP-31642

Description

This is based on downstream 1.0.1 and so will have conflict. Don't expect to merge, only for building the debug image

Testing

Steps to test

  1. Pull down the PR
  2. ...
  3. ...

Scenarios tested

Production deployment

  • This code change is ready for production on its own
  • This code change requires the following considerations before going to production:

@jameswnl jameswnl marked this pull request as draft September 20, 2024 05:02
@jameswnl jameswnl requested a review from hasys September 20, 2024 05:03
@@ -572,7 +581,9 @@
def _get_base_headers(self, api_key: str) -> dict[str, str]:
# https://www.ibm.com/docs/en/cloud-paks/cp-data/4.8.x?topic=apis-generating-api-auth-token
username = settings.ANSIBLE_WCA_USERNAME
logger.info(f"generating token using {api_key}:{username}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (secret)
as clear text.

Copilot Autofix AI 26 days ago

To fix the problem, we need to avoid logging sensitive information such as the api_key. Instead, we can log a generic message that does not include sensitive data. This ensures that the functionality remains the same without exposing sensitive information.

  • Replace the logging statement that includes the api_key with a generic message.
  • Ensure that no sensitive information is logged in any other part of the code.
Suggested changeset 1
ansible_ai_connect/ai/api/model_client/wca_client.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/ansible_ai_connect/ai/api/model_client/wca_client.py b/ansible_ai_connect/ai/api/model_client/wca_client.py
--- a/ansible_ai_connect/ai/api/model_client/wca_client.py
+++ b/ansible_ai_connect/ai/api/model_client/wca_client.py
@@ -583,5 +583,5 @@
         username = settings.ANSIBLE_WCA_USERNAME
-        logger.info(f"generating token using {api_key}:{username}")
+        logger.info("generating token")
         token = base64.b64encode(bytes(f"{username}:{api_key}", "ascii")).decode("ascii")
-        logger.info(f"token generated: {token}")
+        logger.info("token generated")
         return {
EOF
@@ -583,5 +583,5 @@
username = settings.ANSIBLE_WCA_USERNAME
logger.info(f"generating token using {api_key}:{username}")
logger.info("generating token")
token = base64.b64encode(bytes(f"{username}:{api_key}", "ascii")).decode("ascii")
logger.info(f"token generated: {token}")
logger.info("token generated")
return {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
token = base64.b64encode(bytes(f"{username}:{api_key}", "ascii")).decode("ascii")
logger.info(f"token generated: {token}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (secret)
as clear text.

Copilot Autofix AI 26 days ago

To fix the problem, we should avoid logging sensitive information such as tokens or API keys. Instead, we can log a generic message indicating that a token was generated without including the actual token value. This way, we maintain the ability to trace the flow of execution without exposing sensitive data.

  • Replace the log statement on line 586 with a generic message.
  • Ensure that no sensitive information is included in log messages.
Suggested changeset 1
ansible_ai_connect/ai/api/model_client/wca_client.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/ansible_ai_connect/ai/api/model_client/wca_client.py b/ansible_ai_connect/ai/api/model_client/wca_client.py
--- a/ansible_ai_connect/ai/api/model_client/wca_client.py
+++ b/ansible_ai_connect/ai/api/model_client/wca_client.py
@@ -583,5 +583,5 @@
         username = settings.ANSIBLE_WCA_USERNAME
-        logger.info(f"generating token using {api_key}:{username}")
+        logger.info(f"generating token using provided API key and username")
         token = base64.b64encode(bytes(f"{username}:{api_key}", "ascii")).decode("ascii")
-        logger.info(f"token generated: {token}")
+        logger.info("token generated successfully")
         return {
EOF
@@ -583,5 +583,5 @@
username = settings.ANSIBLE_WCA_USERNAME
logger.info(f"generating token using {api_key}:{username}")
logger.info(f"generating token using provided API key and username")
token = base64.b64encode(bytes(f"{username}:{api_key}", "ascii")).decode("ascii")
logger.info(f"token generated: {token}")
logger.info("token generated successfully")
return {
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@hasys
Copy link
Contributor

hasys commented Sep 20, 2024

Hello @jameswnl,

I tried the build locally and build is not working properly for me. When I call completion endpoint in VS Code, I see an error and in console log I this this issues:

System check identified no issues (0 silenced).
September 20, 2024 - 10:04:44
Django version 4.2.16, using settings 'ansible_ai_connect.main.settings.development'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

INFO 2024-09-20 10:06:36,405 wca_client.py:get_api_key API_KEY using settings.ANSIBLE_AI_MODEL_MESH_API_KEY: {KEY_WAS_PROVIDED_CORRECTLY}
INFO 2024-09-20 10:06:36,405 inference.py:process A WCA Model ID was expected but not found for suggestion 5c35db46-6d48-49f2-94d4-7b1468d98560
INFO 2024-09-20 10:06:36,405 segment.py:send_segment_event segment write key not set, skipping event
WARNING 2024-09-20 10:06:36,407 log.py:log_response Forbidden: /api/v0/ai/completions/
WARNING 2024-09-20 10:06:36,408 basehttp.py:log_message "POST /api/v0/ai/completions/ HTTP/1.1" 403 130
WARNING 2024-09-20 10:06:36,408 basehttp.py:log_message "POST /api/v0/ai/completions/ HTTP/1.1" 403 130

But even getting error, I had to get much more context for the request, isn't it?

UPD: I switched to main branch and all works as expected. So issues is whit the old code in the branch, I suppose.

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.

2 participants