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

Support backend access key #154

Merged
merged 12 commits into from
Oct 22, 2023
Merged

Support backend access key #154

merged 12 commits into from
Oct 22, 2023

Conversation

rcohencyberarmor
Copy link
Contributor

@rcohencyberarmor rcohencyberarmor commented Oct 1, 2023

PR Type:

Enhancement


PR Description:

This PR introduces the support for access tokens in the backend adapter. The access token is passed as a parameter to the NewBackendAdapter function and is used for authorization in HTTP requests. The token is also loaded from a secret file. The PR includes changes in the function signatures, tests, and the addition of a new function to set headers for post requests. It also includes updates to dependencies in the go.mod file.


PR Main Files Walkthrough:

files:

adapters/v1/backend.go: The NewBackendAdapter function now accepts an additional parameter for the access token. The getCVEExceptionsFunc and sendStatusFunc functions have been updated to use the access token. The accessToken field has been added to the BackendAdapter struct.
adapters/v1/backend_test.go: The tests have been updated to reflect the changes in function signatures in the backend.go file.
cmd/http/main.go: The access token is now loaded from a secret file and passed to the NewBackendAdapter function.
adapters/v1/backend_utils.go: A new function setPostResultHeaders has been added to set headers for post requests, including the Authorization header using the access token.
config/config.go: Added functions to load and decode the access token from a secret file.
go.mod: The versions of several dependencies have been updated.


User Description:

Overview

rcohencyberarmor added 4 commits September 11, 2023 10:50
Signed-off-by: rcohencyberarmor <rcohen@armosec.io>
Signed-off-by: rcohencyberarmor <rcohen@armosec.io>
@codiumai-pr-agent codiumai-pr-agent bot added the enhancement New feature or request label Oct 1, 2023
@codiumai-pr-agent
Copy link

PR Analysis

  • 🎯 Main theme: Adding support for access tokens in backend adapter
  • 📝 PR summary: This PR introduces the support for access tokens in the backend adapter. The access token is passed as a parameter to the NewBackendAdapter function and is used for authorization in HTTP requests. The token is also loaded from a secret file. The PR includes changes in the function signatures, tests, and the addition of a new function to set headers for post requests. It also includes updates to dependencies in the go.mod file.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: Yes
  • ⏱️ Estimated effort to review [1-5]: 3
    The PR includes changes in multiple files and function signatures, as well as the addition of new functions and updates to dependencies. However, the changes are straightforward and the code is well-structured, which should make the review process relatively easy.
  • 🔒 Security concerns: No
    The PR enhances security by adding support for access tokens. However, it would be beneficial to add error handling for cases where the access token is not provided or is invalid, as suggested above.

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the changes are straightforward. The addition of access token support is a good enhancement for security. However, it would be beneficial to consider error handling for the case where the access token is not provided or is invalid. Also, it would be good to consider the case where the secret file from which the access token is loaded does not exist or cannot be read.

  • 🤖 Code feedback:

    • relevant file: adapters/v1/backend.go
      suggestion: Consider adding error handling for the case where the access token is not provided or is invalid. This could be done by checking if the access token is empty and returning an error in such cases. [important]
      relevant line: accessToken: accessToken,

    • relevant file: cmd/http/main.go
      suggestion: Consider adding error handling for the case where the secret file from which the access token is loaded does not exist or cannot be read. This could be done by checking if the file exists before trying to read from it and returning an error if it does not exist. [important]
      relevant line: sd, err := config.LoadSecret("/etc/access-token-secret")

    • relevant file: adapters/v1/backend_utils.go
      suggestion: Consider adding a check to ensure that the Authorization header is correctly formed. This could be done by checking if the access token is correctly prefixed with "Bearer ". [medium]
      relevant line: "Authorization": "Bearer " + a.accessToken,

How to use

To invoke the PR-Agent, add a comment using one of the following commands:
/review [-i]: Request a review of your Pull Request. For an incremental review, which only considers changes since the last review, include the '-i' option.
/describe: Modify the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest improvements to the code in the PR. Extended mode employs several calls, and provides a more thorough feedback.
/ask <QUESTION>: Pose a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.

To edit any configuration parameter from configuration.toml, add --config_path=new_value
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, use the /config command.

@github-actions
Copy link

github-actions bot commented Oct 1, 2023

Summary:

  • License scan: failure
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

Signed-off-by: Amir Malka <amirm@armosec.io>
Signed-off-by: Amir Malka <amirm@armosec.io>
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

Summary:

  • License scan: failure
  • Credentials scan: success
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: success

Signed-off-by: Amir Malka <amirm@armosec.io>
Signed-off-by: Amir Malka <amirm@armosec.io>
adapters/v1/backend_utils.go Outdated Show resolved Hide resolved
@dwertent dwertent added the release Create release label Oct 18, 2023
Signed-off-by: Amir Malka <amirm@armosec.io>
@amirmalka amirmalka self-assigned this Oct 18, 2023
…kend-access-token

Signed-off-by: Amir Malka <amirm@armosec.io>
dwertent
dwertent previously approved these changes Oct 18, 2023
Signed-off-by: Amir Malka <amirm@armosec.io>
Signed-off-by: Amir Malka <amirm@armosec.io>
@amirmalka amirmalka changed the title Support backend access token Support backend access key Oct 19, 2023
@amirmalka amirmalka merged commit e2b2c6f into main Oct 22, 2023
2 of 3 checks passed
@dwertent dwertent deleted the support-backend-access-token branch December 13, 2023 11:01
dwertent pushed a commit that referenced this pull request Dec 31, 2023
Support backend access key

Signed-off-by: Amir Malka <amirm@armosec.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request release Create release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants