GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix: Remove UTF-8 encoding to prevent mangling of binary secrets by matthiasfehr · Pull Request #599 · docker/actions-toolkit

Conversation

@matthiasfehr

@matthiasfehr matthiasfehr commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

This PR removes the explicit encoding: 'utf-8' from the secret resolution code to ensure binary files are not corrupted. Previously, reading and writing secrets as UTF-8 caused issues when the secret was a binary file. By switching to raw buffers, the code now correctly supports both binary and text-based secrets without any unintended transformations.

  • Removed encoding: 'utf-8' from fs.readFileSync.
  • Ensured raw buffers are used when reading and writing secrets, preventing data corruption.
  • Maintains existing behavior for text-based secrets, while adding proper support for binary data.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@matthiasfehr
matthiasfehr force-pushed the binary-secret-files branch from 3d670fa to ed85272 Compare February 19, 2025 10:53
@crazy-max

crazy-max commented Feb 19, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR removes the explicit encoding: 'utf-8' from the secret resolution code to ensure binary files are not corrupted.

I was looking at the initial implementation and it was added in https://github.com/docker/build-push-action/pull/296/files#diff-f73f5f656aeb1aac9f0e62af243004b96603175d3d897231961ab4245d7a5a50R41

I think your change is fine but I just wonder what's your use case to have a bin formatted secret to use in your Dockerfile. Do you mind to share?

Also I think instead of doing both fs.readFileSync and fs.writeFileSync we could just do a fs.copyFileSync for file-based secrets like:

  public static resolveSecret(kvp: string, file: boolean): [string, string] {
    const [key, value] = Build.parseSecretKvp(kvp);
    const secretFile = Context.tmpName({tmpdir: Context.tmpDir()});
    if (file) {
      if (!fs.existsSync(value)) {
        throw new Error(`secret file ${value} not found`);
      }
      fs.copyFileSync(value, secretFile);
    } else {
      fs.writeFileSync(secretFile, value);
    }
    return [key, secretFile];
  }
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@matthiasfehr

matthiasfehr commented Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

I have a docker build stage in my Dockerfile where I sign the built executable, and for this I need to pass in a p12 certificate file. This works when directly passed as secret argument to docker but not with this action.

I have updated the PR to use directly the copyFileSync method.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

crazy-max
crazy-max reviewed Feb 19, 2025
View reviewed changes

@crazy-max crazy-max left a comment

Copy link
Copy Markdown
Member

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.

Can you squash your commits? Otherwise LGTM thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@matthiasfehr
support binary data when copying secret files
9692462
Signed-off-by: Matthias Fehr <[email protected]>
@matthiasfehr
matthiasfehr force-pushed the binary-secret-files branch from 9de7219 to 9692462 Compare February 19, 2025 13:19
crazy-max
crazy-max approved these changes Feb 19, 2025
View reviewed changes
@crazy-max
crazy-max merged commit ea9281e into docker:main Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@crazy-max crazy-max crazy-max approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@matthiasfehr @crazy-max
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.