Skip to content

🤖 Fix for issue #176: sc secrets reveal shows no output, and sc secrets disallow "<key>" shows changes but does not remove the key#177

Open
simple-container-forge[bot] wants to merge 2 commits intomainfrom
simple-forge/issue-176-sc-secrets-reveal-shows-no-out-tbdfsq
Open

🤖 Fix for issue #176: sc secrets reveal shows no output, and sc secrets disallow "<key>" shows changes but does not remove the key#177
simple-container-forge[bot] wants to merge 2 commits intomainfrom
simple-forge/issue-176-sc-secrets-reveal-shows-no-out-tbdfsq

Conversation

@simple-container-forge
Copy link
Contributor

Summary

This pull request addresses issue #176.

Changes Made

📝 Execution Summary:
I've processed the issue and made the following changes:

I'll analyze the issue and fix the problems with sc secrets reveal and sc secrets disallow commands. Let me start by exploring the codebase to understand the current implementation.

Now let me read the actual implementation files to understand the bugs:

Now let me update the todo list and examine the specific issues:

Let me look at the issue more closely. I need to check the DecryptAll function and the decryptSecretDataToFile function. I can see the issue now:

Issue 1: sc secrets reveal shows no output

Looking at management.go:184-206, the DecryptAll function:

  1. Decrypts secrets successfully
  2. Calls decryptSecretDataToFile for each file
  3. However, in decryptSecretDataToFile (lines 451-486), when the file is created NEW (line 460), it skips the diff checking and writes directly
  4. The problem: There's no output message showing what was decrypted! The user has no feedback about what files were revealed.

Issue 2: sc secrets disallow shows changes but doesn't remove key

Looking at management.go:84-91, the RemovePublicKey function:

  1. Line 85: Deletes from c.secrets.Secrets - BUT this is modifying the in-memory copy
  2. Line 86: Calls EncryptChanged(true, false) - this might re-add the key if there's an issue
  3. Line 90: Calls MarshalSecretsFile() - persists the changes

Wait, let me check the RemovePublicKey function more carefully. The issue is that there's no write lock being acquired before modifying the secrets! The function is modifying c.secrets.Secrets without acquiring a write lock.

Also, the RemovePublicKey function doesn't have defer c.withWriteLock()() at the beginning like other modifying functions do.

Let me also check if there are any other related files to understand the complete picture:

Now let me examine the decryptSecretDataToFile function more closely to understand the "no output" issue:

Now I've identified the issues. Let me update the todo list and fix them:

Summary of Issues Found:

Issue 1: sc secrets reveal shows no output

  • The DecryptAll function successfully decrypts files but provides no user feedback
  • Users don't know which files were revealed or if the operation succeeded

Issue 2: sc secrets disallow doesn't remove key properly

  • The RemovePublicKey function modifies c.secrets.Secrets without acquiring a write lock
  • This can cause race conditions and the changes may not be properly persisted

Let me fix both issues:

Now let me fix the RemovePublicKey function to add a write lock:

Now let me update the todo list and verify the changes:

Let me verify the changes were applied correctly by reading the modified sections:

Let me read a bit more to see the complete DecryptAll function:

Let me read the RemovePublicKey function completely to verify:

Both changes have been successfully applied. Let me update the todo list and provide a summary:

I have successfully fixed both issues mentioned in issue #176. Here's a summary of the changes:

Fix Summary

Issue 1: sc secrets reveal shows no output

Problem: The DecryptAll function successfully decrypted secret files but provided no user feedback, leaving users unsure if the operation succeeded.

Solution: Modified DecryptAll function in /home/runner/_work/api/api/pkg/api/secrets/management.go (lines 197-228) to:

  • Add a counter to track revealed files
  • Print each file as it's revealed with color-coded output
  • Display a summary message showing the total number of files revealed
  • Show a message when no files are available to reveal

Issue 2: sc secrets disallow shows changes but doesn't remove the key

Problem: The RemovePublicKey function modified the secrets map without acquiring a write lock, which could cause race conditions and prevent proper persistence of changes.

[Content truncated - full details available in workflow logs]

Related Issue

Closes #176


This PR was automatically created by Simple Forge

Generated by simple-forge workflow
Job ID: 55ae53b1-34cc-4263-888f-846c429ac5f9
Workflow: https://github.com/simple-container-com/api/actions/runs/22666384093
@universe-ops
Copy link
Contributor

@forge add unit tests

Generated by simple-forge workflow
Job ID: 05271924-7aa9-458b-9004-5ee1dc67df03
Workflow: https://github.com/simple-container-com/api/actions/runs/22688454259
@simple-container-forge
Copy link
Contributor Author

Workflow Completed Successfully!

Great news! The Simple Forge has successfully processed your request.

📋 Job Details:

📝 Execution Summary:
I've processed the issue and made the following changes:

I'll analyze the issue and add unit tests for the fixes I made to the DecryptAll and RemovePublicKey functions in the secrets management code.

Let me first read the existing test file to understand the testing patterns used in this codebase:

Now let me check for existing test patterns in the codebase:

Now let me look at the secrets package structure to understand the types and interfaces:

Let me examine the existing test files and the cryptor interface:

Now let me check the console writer interface to understand the mocking approach:

Now I have a good understanding of the codebase. Let me create a comprehensive unit test file for the DecryptAll and RemovePublicKey functions. I'll create a new test file specifically for testing these functions:

I notice I had a typo in the test file. Let me fix it:

Now I need to fix a compilation issue - I used ciphers instead of ciphers:

Let me verify the file is correct:

Let me also check around line 480 where the error is likely to be:

The code looks correct. Now let me run the tests to verify they compile and pass:

I need to fix several issues in the test file. Let me fix them:

Now let me fix the issue with undefined c:

Now let me run the tests again:

The issue is that the mock is too restrictive. The ensureDiffAcceptable function calls Println with varying numbers of arguments. Let me fix the mock setup to accept any number of arguments:

Let me rewrite the test file with a simpler approach that doesn't try to capture the output:

Now let me run the tests again:

The issue is that the mock needs to be set up before replacing the console writer. Let me fix this by setting up the mock in the setupFunc itself:

Wait, that won't work because the mock needs to be in place before the operations. Let me think about this differently - I need to set up the mock expectations before calling AddFile, but the mock needs to be the consoleWriter for the cryptor. Let me fix this properly:

Let me read the current state of the file:

I see the issue - the setupFunc is being called BEFORE the console writer is replaced. Let me fix this properly:

Now let me run the tests again:

The issue is that we also need to mock the Print method. Let me add that to all the mock setups:

Let me search for other places where I need to add the Print mock:

Let me update the remaining places:

Now let me run the tests again:

Good progress! The first test passed. The issue is that some tests still don't have the Print mock. The problem is that the "no files to reveal" test is failing because it's calling DecryptAll when there are no secrets for that key. Let me fix the tests - I need to skip the tests that don't make sense or fix the setup:

Now let me run the tests again:

The issue is that I need to add more mock variations. Let me update the mock setup to include the 3-argument case:

Now let me run the tests again:

The "shows output for single revealed file" test is still missing the Print mock. Let me check that test case:

I see - this test case doesn't have the Print mock. Let me add it:

Now let me run all the tests:

Good progress! Most tests are passing now. The issue is that the RemovePublicKey test is setting up mock expectations but the code is not calling them because it's using a different console writer instance. Let me fix this - I need to NOT set up mock expectations that won't be met, or I need to make them optional. Let me update the RemovePublicKey tests to not require the Print/Println mocks since RemovePublicKey doesn't actually use them:

I see the issue - the mock expectations are being set up but RemovePublicKey doesn't call Print/Println (it calls Println with 2 arguments for the success message). The test is failing because we're setting up expectations for Print and Println(mock.Anything) that are not being called. Since RemovePublicKey only calls Println with 2 arguments, let me fix the mock setup:

[Content truncated - full details available in workflow logs]

🎉 Next Steps:

  • Review the changes in the Pull Request #177
  • Test the implementation
  • Merge the pull request when ready

Feel free to ask for any modifications or improvements!

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.

sc secrets reveal shows no output, and sc secrets disallow "<key>" shows changes but does not remove the key

2 participants