Skip to content

fix: sonar security issue #961

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.javaoperatorsdk.operator.sample;

import java.security.SecureRandom;
import java.util.Base64;
import java.util.Optional;

import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -43,8 +44,7 @@ public MySQLSchemaReconciler() {}
@Override
public void initContext(MySQLSchema primary, Context context) {
final var name = primary.getMetadata().getName();
// NOSONAR we don't need cryptographically-strong randomness here
final var password = RandomStringUtils.randomAlphanumeric(16);
final var password = randomPassword(16);
final var secretName = String.format(SECRET_FORMAT, name);
final var userName = String.format(USERNAME_FORMAT, name);

Expand All @@ -54,6 +54,13 @@ public void initContext(MySQLSchema primary, Context context) {
context.put(MYSQL_SECRET_USERNAME, userName);
}

private String randomPassword(int length) {
SecureRandom random = new SecureRandom(); // Compliant for security-sensitive use cases
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't need to do this, though… We need a way to exclude such false positive from Sonar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did not find a way, not sure if possible for the security issues.

Copy link
Collaborator Author

@csviri csviri Feb 21, 2022

Choose a reason for hiding this comment

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

this seems to be working:
#962
:)

byte bytes[] = new byte[length];
random.nextBytes(bytes);
return Base64.getEncoder().encodeToString(bytes);
}

@Override
public UpdateControl<MySQLSchema> reconcile(MySQLSchema schema, Context context) {
// we only need to update the status if we just built the schema, i.e. when it's present in the
Expand Down