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

Kubero V3 refactoring #619

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

Kubero V3 refactoring #619

wants to merge 72 commits into from

Conversation

mms-gianni
Copy link
Member

@mms-gianni mms-gianni commented Jan 31, 2025

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Template (non-breaking change which adds a template)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • I've built the image and tested it on a kubernetes cluster

Test Configuration:

  • Operator Version:
  • Kubernetes Version:
  • Kubero CLI Version (if applicable):

Checklist:

  • I removed unnecessary debug logs
  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I documented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Sorry, something went wrong.

@mms-gianni mms-gianni marked this pull request as draft January 31, 2025 13:34
…ith kubero v2.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
(WIP) add initial auth function
@mms-gianni mms-gianni self-assigned this Feb 3, 2025
@mms-gianni mms-gianni added the in progress working on it label Feb 3, 2025
@mms-gianni mms-gianni linked an issue Feb 3, 2025 that may be closed by this pull request
@mms-gianni
Copy link
Member Author

Progress

image

mms-gianni and others added 17 commits February 14, 2025 14:30

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
… in path expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ain-refactored

const password = crypto
.createHmac('sha256', process.env.KUBERO_SESSION_KEY)
.update(pass)

Check failure

Code scanning / CodeQL

Use of password hash with insufficient computational effort High

Password from
an access to password
is hashed insecurely.
Password from
an access to password
is hashed insecurely.
Password from
an access to password
is hashed insecurely.

Copilot Autofix AI about 11 hours ago

To fix the problem, we need to replace the current password hashing method with a more secure one, such as bcrypt. This will involve:

  1. Importing the bcrypt library.
  2. Updating the validateUser method to use bcrypt for password comparison.
  3. Ensuring that the bcrypt library is installed as a dependency.
Suggested changeset 1
server-refactored-v3/src/auth/auth.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server-refactored-v3/src/auth/auth.service.ts b/server-refactored-v3/src/auth/auth.service.ts
--- a/server-refactored-v3/src/auth/auth.service.ts
+++ b/server-refactored-v3/src/auth/auth.service.ts
@@ -13,3 +13,3 @@
 import { JwtService } from '@nestjs/jwt';
-import * as crypto from 'crypto';
+import * as bcrypt from 'bcrypt';
 
@@ -36,7 +36,4 @@
 
-      const password = crypto
-        .createHmac('sha256', process.env.KUBERO_SESSION_KEY)
-        .update(pass)
-        .digest('hex');
-      if (user.password === password) {
+      const passwordMatch = await bcrypt.compare(pass, user.password);
+      if (passwordMatch) {
         const { password, ...result } = user;
EOF
@@ -13,3 +13,3 @@
import { JwtService } from '@nestjs/jwt';
import * as crypto from 'crypto';
import * as bcrypt from 'bcrypt';

@@ -36,7 +36,4 @@

const password = crypto
.createHmac('sha256', process.env.KUBERO_SESSION_KEY)
.update(pass)
.digest('hex');
if (user.password === password) {
const passwordMatch = await bcrypt.compare(pass, user.password);
if (passwordMatch) {
const { password, ...result } = user;
Copilot is powered by AI and may make mistakes. Always verify output.

Provide additional feedback

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

);
password = crypto
.createHmac('sha256', process.env.KUBERO_SESSION_KEY)
.update(password)

Check failure

Code scanning / CodeQL

Use of password hash with insufficient computational effort High

Password from
an access to password
is hashed insecurely.
Password from
an access to password
is hashed insecurely.

Copilot Autofix AI 24 days ago

To fix the problem, we should replace the use of crypto.createHmac('sha256', ...) with a more secure password hashing scheme such as bcrypt. This will ensure that the password hashing process requires significant computational effort, making it more resistant to brute-force attacks.

The best way to fix the problem without changing existing functionality is to use the bcrypt library to hash the passwords. We will need to import the bcrypt library, update the password hashing logic to use bcrypt.hashSync, and ensure that the salt is properly generated and used.

Suggested changeset 1
server-refactored-v3/src/users/users.service.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server-refactored-v3/src/users/users.service.ts b/server-refactored-v3/src/users/users.service.ts
--- a/server-refactored-v3/src/users/users.service.ts
+++ b/server-refactored-v3/src/users/users.service.ts
@@ -3,3 +3,3 @@
 dotenv.config();
-import * as crypto from 'crypto';
+import * as bcrypt from 'bcrypt';
 
@@ -45,6 +45,4 @@
           );
-          password = crypto
-            .createHmac('sha256', process.env.KUBERO_SESSION_KEY)
-            .update(password)
-            .digest('hex');
+          const saltRounds = 10;
+          password = bcrypt.hashSync(password, saltRounds);
         }
EOF
@@ -3,3 +3,3 @@
dotenv.config();
import * as crypto from 'crypto';
import * as bcrypt from 'bcrypt';

@@ -45,6 +45,4 @@
);
password = crypto
.createHmac('sha256', process.env.KUBERO_SESSION_KEY)
.update(password)
.digest('hex');
const saltRounds = 10;
password = bcrypt.hashSync(password, saltRounds);
}
Copilot is powered by AI and may make mistakes. Always verify output.

Provide additional feedback

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress working on it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Announcing Kubero v3 (Refactoring)
1 participant