@okmon1222

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

GItHubでcommitできるようにしたい。

Q&A

Closed

解決したいこと

Windowsのパソコンを使用しています。S3に保存する処理の過程で環境変数を間違ってGitHubに保存したときに警告が発生し保存できないようgit-secretsをダウンロードし設定をしたのですが、パスワードらしき文字も入れていないのに警告文がでて保存できません。

発生している問題・エラー

git: 'secrets' is not a git command. See 'git --help'.

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

該当するソースコード

config_storage.yml
  access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
  secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
  
ターミナル
git secrets --list
secrets.providers git secrets --aws-provider
secrets.patterns (A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}
secrets.patterns ("|')?(AWS|aws|Aws)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)("|')?\s*(:|=>|=)\s*("|')?[A-Za-z0-9/\+=]{40}("|')?
secrets.patterns ("|')?(AWS|aws|Aws)?_?(ACCOUNT|account|Account)_?(ID|id|Id)?("|')?\s*(:|=>|=)\s*("|')?[0-9]{4}\-?[0-9]{4}\-?[0-9]{4}("|')?
secrets.allowed AKIAIOSFODNN7EXAMPLE
secrets.allowed wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

自分で試したこと

パスワードのような文に反応するとあったので、GitHubで変更した部分を調べましたが、引っ掛かりそうな文はありませんでした。
コマンドを再度入れてみて確かめたのですが、ダウンロードはできているようです。

パソコンはWindowsを使用し、rails 7.0.0を使用し勉強中の身です

0 likes

2Answer

「git-secretsをダウンロードし設定をした」とありますが、インストールは行いましたか?

PS > ./install.ps1
0Like

Comments

  1. @okmon1222

    Questioner

    コメントありがとうございます。Windowsのパソコンなのでインストールはコマンドプロンプトにwinget install --id Git.Git -e --source wingetを入力しGITをインストール、
    winget install --id Microsoft.Powershell --source wingetを入力してPowerShellをインストールしました。その後、PowerShell7に以下の手順でgit-secretsをインストールしました。
    % cd
    % git clone https://github.com/awslabs/git-secrets
    % cd git-secrets
    % ./install.ps1
    教材通りにしたのですが、なにか問題があったのでしょうか?教えていただけるとありがたいです。

  2. install.ps1 を実行すると下記のようになるはずです。

    PS C:\Users\ita\source\repos\git-secrets> .\install.ps1
    Checking to see if installation directory already exists...
    Creating installation directory.
    Copying files.
    Checking if directory already exists in Path...
    Adding to path.
    Adding to user session.
    Done.
    
    

    インストールが正常にできていたら、git secrets を実行すると下記のようになるはずです。

    PS C:\Users\ita\source\repos\git-secrets> git secrets
    usage: git secrets --scan [-r|--recursive] [--cached] [--no-index] [--untracked] [<files>...]
       or: git secrets --scan-history
       or: git secrets --install [-f|--force] [<target-directory>]
       or: git secrets --list [--global]
       or: git secrets --add [-a|--allowed] [-l|--literal] [--global] <pattern>
       or: git secrets --add-provider [--global] <command> [arguments...]
       or: git secrets --register-aws [--global]
       or: git secrets --aws-provider [<credentials-file>]
    
        --[no-]scan           Scans <files> for prohibited patterns
        --[no-]scan-history   Scans repo for prohibited patterns
        --[no-]install        Installs git hooks for Git repository or Git template directory
        --[no-]list           Lists secret patterns
        --[no-]add            Adds a prohibited or allowed pattern, ensuring to de-dupe with existing patterns
        --[no-]add-provider   Adds a secret provider that when called outputs secret patterns on new lines
        --[no-]aws-provider   Secret provider that outputs credentials found in an ini file
        --[no-]register-aws   Adds common AWS patterns to the git config and scans for ~/.aws/credentials
        -r, --[no-]recursive  --scan scans directories recursively
        --[no-]cached         --scan scans searches blobs registered in the index file
        --no-index            --scan searches files in the current directory that is not managed by Git
        --index               opposite of --no-index
        --[no-]untracked      In addition to searching in the tracked files in the working tree, --scan also in untracked files
        -f, --[no-]force      --install overwrites hooks if the hook already exists
        -l, --[no-]literal    --add and --add-allowed patterns are escaped so that they are literal
        -a, --[no-]allowed    --add adds an allowed pattern instead of a prohibited pattern
        --[no-]global         Uses the --global git config
    
    

    インストールできていながら、こうならずエラーになるとしたら、環境変数 PATH が正しくない可能性があります。PATH.git-secrets がある(私の場合だと C:\Users\ita\.git-secrets)ことを確認してください。

    もしかして、git secrets の実行を試されたシェルは上記のインストールによって PATH.git-secrets が追加される前に起動したままのシェルではないですか?もしそうなら新たなシェルを起動して試してみてください。

  3. @okmon1222

    Questioner

    PS C:\Users\owner\git-secrets> git secrets
    usage: git secrets --scan [-r|--recursive] [--cached] [--no-index] [--untracked] [<files>...]
       or: git secrets --scan-history
       or: git secrets --install [-f|--force] [<target-directory>]
       or: git secrets --list [--global]
       or: git secrets --add [-a|--allowed] [-l|--literal] [--global] <pattern>
       or: git secrets --add-provider [--global] <command> [arguments...]
       or: git secrets --register-aws [--global]
       or: git secrets --aws-provider [<credentials-file>]
    
        --[no-]scan           Scans <files> for prohibited patterns
        --[no-]scan-history   Scans repo for prohibited patterns
        --[no-]install        Installs git hooks for Git repository or Git template directory
        --[no-]list           Lists secret patterns
        --[no-]add            Adds a prohibited or allowed pattern, ensuring to de-dupe with existing patterns
        --[no-]add-provider   Adds a secret provider that when called outputs secret patterns on new lines
        --[no-]aws-provider   Secret provider that outputs credentials found in an ini file
        --[no-]register-aws   Adds common AWS patterns to the git config and scans for ~/.aws/credentials
        -r, --[no-]recursive  --scan scans directories recursively
        --[no-]cached         --scan scans searches blobs registered in the index file
        --no-index            --scan searches files in the current directory that is not managed by Git
        --index               opposite of --no-index
        --[no-]untracked      In addition to searching in the tracked files in the working tree, --scan also in untracked files
        -f, --[no-]force      --install overwrites hooks if the hook already exists
        -l, --[no-]literal    --add and --add-allowed patterns are escaped so that they are literal
        -a, --[no-]allowed    --add adds an allowed pattern instead of a prohibited pattern
        --[no-]global         Uses the --global git config`
    
    

    インストールはできているようです。シェルもインストールしてからひらいています。環境変数の確認もしましたが、間違いなく設定できています。そのほかに考えられる原因があれば教えてください。何度もすみませんがよろしくお願いします。

Your answer might help someone💌