<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: jeremy-kaltenbach</title>
    <description>The latest articles on Forem by jeremy-kaltenbach (@jeremykaltenbach).</description>
    <link>https://forem.com/jeremykaltenbach</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F725660%2Fb3bf830e-d47e-4b54-8b9d-4e87a1cfb1ea.jpg</url>
      <title>Forem: jeremy-kaltenbach</title>
      <link>https://forem.com/jeremykaltenbach</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jeremykaltenbach"/>
    <language>en</language>
    <item>
      <title>Masking Input Parameters in GitHub Actions</title>
      <dc:creator>jeremy-kaltenbach</dc:creator>
      <pubDate>Wed, 26 Apr 2023 17:45:45 +0000</pubDate>
      <link>https://forem.com/leading-edje/masking-input-parameters-in-github-actions-1ci</link>
      <guid>https://forem.com/leading-edje/masking-input-parameters-in-github-actions-1ci</guid>
      <description>&lt;p&gt;GitHub actions allow you to add input parameters, which will then be used during runtime of the workflow. The inputs can be passed from a different workflow that is calling the specified workflow (via the &lt;code&gt;workflow_call&lt;/code&gt; event) or when the workflow is manually triggered (via &lt;code&gt;workflow_dispatch&lt;/code&gt;). For the latter, GitHub will  prompt for the inputs in a dialog box before kicking off the workflow.&lt;/p&gt;

&lt;p&gt;Note that in the workflow logs, the input parameters will be logged in plain text. So what do we do if one or more inputs contain sensitive information? The common approach would be to use &lt;a href="https://docs.github.com/en/rest/actions/secrets" rel="noopener noreferrer"&gt;Secrets&lt;/a&gt;. These are very useful for encrypting sensitive information, such as API keys and will not be logged in plain sight.&lt;/p&gt;

&lt;p&gt;But lets say there is a use-case where a manual workflow will be triggered by multiple users supplying their own credentials. Inputs would be an easier solution here instead of having to frequently update the secrets. Luckily there is a way to make sure those sensitive inputs don't get logged.&lt;/p&gt;

&lt;p&gt;In the example below, we have a workflow that will prompt the user for their username and password, and then it will call an API using  those credentials (with the help of the &lt;a href="https://github.com/marketplace/actions/http-request-action" rel="noopener noreferrer"&gt;http-request-action&lt;/a&gt;). The username input is safe to log, but the password should not be shown.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Call API Example

on:
  workflow_dispatch:
    inputs:
      username:
        required: true
        type: string
      password:
        required: true
        type: string

jobs:
  do_the_thing:
    runs-on: ubuntu-latest
    steps:
    - name: Mask Password
      run: |
        API_PASSWORD=$(jq -r '.inputs.password' $GITHUB_EVENT_PATH)
        echo ::add-mask::$API_PASSWORD
        echo API_PASSWORD=$API_PASSWORD &amp;gt;&amp;gt; $GITHUB_ENV
    - name: Call API
      uses: fjogeleit/http-request-action@v1.11.1
      with:
        url: https://www.example.com/api/awesome/stuff
        method: 'POST'
        username: ${{ github.event.inputs.username }}
        password: ${{ env.API_PASSWORD }}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To mask the password, a step will need to be added before calling the API. In the step, "Mask Password", we'll make use of the workflow command &lt;a href="https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#masking-a-value-in-log" rel="noopener noreferrer"&gt;::ask-mask::{value}&lt;/a&gt;.&lt;br&gt;
Unfortunately, calling add-mask on the input directly (such as &lt;code&gt;::add-mask::${{ github.event.inputs.password }}&lt;/code&gt;) will still expose the input in the log (more info on the bug here: &lt;a href="https://github.com/actions/runner/issues/643" rel="noopener noreferrer"&gt;https://github.com/actions/runner/issues/643&lt;/a&gt;). But as a workaround, the input parameter needs to first be set to a variable. Then calling add-mask on that variable will properly mask it. &lt;br&gt;
In the workflow example, the 'password' input is first assigned to the variable named &lt;code&gt;API_PASSWORD&lt;/code&gt;. Then the add-mask command called with the variable. Finally, &lt;code&gt;API_PASSWORD&lt;/code&gt; is set as an environment variable to be used in any following steps of the job.&lt;/p&gt;

&lt;p&gt;The output log will then look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; Mask Password
Run API_PASSWORD=$(jq -r '.inputs.password' $GITHUB_EVENT_PATH)
  API_PASSWORD=$(jq -r '.inputs.password' $GITHUB_EVENT_PATH)
  echo ::add-mask::$API_PASSWORD
  echo API_PASSWORD=$API_PASSWORD &amp;gt;&amp;gt; $GITHUB_ENV
  shell: /usr/bin/bash -e {0}

&amp;gt; Call API
Run fjogeleit/http-request-action@v1.11.1
  with:
    url: https://www.example.com/api/awesome/stuff
    method: POST
    username: bobsmith
    password: ***
    data: {}
    files: {}
    timeout: 5000
  env:
    API_PASSWORD: ***
…
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>rest</category>
      <category>programming</category>
      <category>development</category>
    </item>
  </channel>
</rss>
