-
Notifications
You must be signed in to change notification settings - Fork 21
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
Feat: Add mtls authentication for the API #87
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduced in this pull request enhance the Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
op-defender/psp_executor/cli.go (2)
102-119
: Improve usage descriptions for TLS flagsThe new TLS flags are added correctly. However, consider enhancing the
Usage
descriptions for clarity and consistency with existing flags.Suggested changes:
&cli.StringFlag{ Name: optls.TLSCaCertFlagName, - Usage: "tls ca cert path", + Usage: "TLS CA certificate file path", EnvVars: opservice.PrefixEnvVar(envPrefix, "TLS_CA"), }, &cli.StringFlag{ Name: optls.TLSCertFlagName, - Usage: "tls cert path", + Usage: "TLS certificate file path", EnvVars: opservice.PrefixEnvVar(envPrefix, "TLS_CERT"), }, &cli.StringFlag{ Name: optls.TLSKeyFlagName, - Usage: "tls key", + Usage: "TLS key file path", EnvVars: opservice.PrefixEnvVar(envPrefix, "TLS_KEY"), },This improves readability and maintains consistency with the capitalization and descriptive style used in other flags.
102-119
: Explicitly specify theRequired
field for TLS flagsCurrently, the new TLS flags do not have the
Required
field specified. To enhance clarity, explicitly setRequired: false
since these flags are optional.Example:
&cli.StringFlag{ Name: optls.TLSCaCertFlagName, Usage: "TLS CA certificate file path", EnvVars: opservice.PrefixEnvVar(envPrefix, "TLS_CA"), + Required: false, },
Apply the same addition to the
TLSCertFlagName
andTLSKeyFlagName
flags.op-defender/psp_executor/defender.go (1)
601-630
: Consider allowing unauthenticated access to the health check endpointCurrently, the server is configured to require mutual TLS authentication for all endpoints, including
/api/healthcheck
. This may prevent unauthenticated clients from accessing the health check endpoint, which is often needed for monitoring and health checks without authentication.Consider configuring the server or implementing middleware to allow certain endpoints, like
/api/healthcheck
, to bypass mutual TLS authentication while keeping the rest of the API endpoints secured with mTLS.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- op-defender/cmd/defender/cli.go (1 hunks)
- op-defender/psp_executor/cli.go (4 hunks)
- op-defender/psp_executor/defender.go (4 hunks)
🔇 Additional comments (7)
op-defender/cmd/defender/cli.go (2)
Line range hint
1-78
: Verify mTLS implementation in related filesWhile this file now includes a validation step for the configuration, which is a positive change, the mTLS implementation mentioned in the PR objectives is not directly visible here.
To ensure that mTLS is properly implemented, let's examine related files:
#!/bin/bash # Description: Search for mTLS-related code in the project # Test 1: Search for mTLS configuration in Config struct ast-grep --lang go --pattern 'type Config struct { $$$ // Look for fields related to mTLS $_ $_ $$$ }' # Test 2: Search for mTLS setup in server initialization rg --type go -A 10 'func New.*Server' # Test 3: Search for mTLS-related flags rg --type go 'cli\.StringFlag.*mTLS'These checks will help verify that mTLS is properly configured and implemented across the project.
59-61
: Approve: Good addition of configuration validationThe addition of the
cfg.Check()
call improves the robustness of the application by ensuring that only valid configurations are processed. This aligns well with the PR objectives of enhancing security and reliability.Consider enhancing the error handling to provide more context:
if err := cfg.Check(); err != nil { - return nil, err + return nil, fmt.Errorf("invalid configuration: %w", err) }This will make debugging easier by providing more information about the nature of the configuration error.
To ensure that the
cfg.Check()
method includes all necessary validations, especially for mTLS, let's examine its implementation:op-defender/psp_executor/cli.go (5)
5-5
: Import statement for TLS configuration added correctlyThe import of the
optls
package is necessary for TLS configuration and is appropriately included.
30-30
: Addition ofTLSConfig
field toCLIConfig
structThe
TLSConfig
field is added to theCLIConfig
struct to incorporate TLS settings, aligning with the objective of introducing mTLS authentication.
43-43
: InitializeTLSConfig
inReadCLIFlags
functionThe
TLSConfig
field is properly initialized usingoptls.ReadCLIConfig(ctx)
, ensuring that TLS configurations are read from the CLI context.
50-50
: RefactorCLIFlags
function to use a localflags
variableAssigning the initial flags to a local variable
flags
allows for appending additional flags later, which is necessary for incorporating the new TLS flags.
123-128
: EnsureTLSConfig.Check()
handles optional TLS configurationIf mTLS is optional, verify that the
Check()
method ofTLSConfig
does not return an error when TLS settings are not provided.Run the following script to confirm that the application initializes correctly without TLS configurations:
This ensures that the application remains functional when mTLS is not enabled, and
TLSConfig.Check()
handles the absence of TLS settings gracefully.
Thanks a lot for the contribution @nodauf! I will try update the doc into the current branch. |
Description
This PR add mTLS authentication for the API (#77). The
op-service
from the monorepo already implements the necessary requirements for this. I made a few adjustments since the default values are set for the TLS flags (default values). As a result, the checks (checks) always indicated that TLS was enabled, even when the user didn't provide the arguments.Regarding your infrastructure, I'm not sure if using middleware might be a better option than what I implemented. The middleware could allow some endpoints (like the healthcheck) to bypass the mTLS. What are you though on this?
Tests
The feature was tested using the following command line:
And then it was confirmed that only client that are authenticated using a certificate can access the API:
The files used in the previous command can be found below:
certs.zip
Metadata
psp_executor
HTTP API intoop-defender
#77Summary by CodeRabbit
New Features
Bug Fixes