Skip to content

Commit

Permalink
Update README and Actions workflows
Browse files Browse the repository at this point in the history
Update README. Don't build on irrelevant changes, add publish to github packages, configure workflow permissions.
  • Loading branch information
chtzvt committed Feb 6, 2023
1 parent c737f8a commit 16351aa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
name: Ruby
name: Build

on:
push:
branches:
- master

paths-ignore:
- '.**'
- 'LICENSE'
- 'ACKNOWLEDGEMENTS'
- '**.md'
- '**.txt'
- '**.yml'
pull_request:
paths-ignore:
- '.**'
- 'LICENSE'
- 'ACKNOWLEDGEMENTS'
- '**.md'
- '**.txt'
- '**.yml'

jobs:
build:
Expand Down
31 changes: 16 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
name: publish
name: Publish

on:
release:
types: [published]

permissions:
actions: read
contents: read
checks: read
packages: write
statuses: write

jobs:
setup:
name: Set Up Environment
publish-ghp:
name: Publish Gem to GitHub Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2.0"
bundler-cache: true
- run: bundle install

publish-ghp:
needs: [setup]
name: Publish Gem
runs-on: ubuntu-latest
steps:
- name: Publish
shell: bash
- shell: bash
run: |
set +x
mkdir -p ~/.gem
cat << EOF > ~/.gem/credentials
---
:github: Bearer ${{ GITHUB_TOKEN }}
:rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}
:github: Bearer ${{ secrets.GITHUB_TOKEN }}
:rubygems: ${{ secrets.RUBYGEMS_API_KEY }}
EOF
chmod 0600 ~/.gem/credentials
set -x
bundle exec gem build *.gemspec
bundle exec gem push --key github --host "https://rubygems.pkg.github.com/chtzvt"
bundle exec gem push --key rubygems_api_key --host "https://rubygems.org"
bundle exec gem push *.gem --key github --host "https://rubygems.pkg.github.com/chtzvt"
# bundle exec gem push *.gem --key rubygems --host "https://rubygems.org" - Need to work out OTP codes
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Sssecrets

Welcome to sssecrets: **S**imple **S**tructured **Secrets**.
[![Gem Version](https://badge.fury.io/rb/sssecrets.svg)](https://badge.fury.io/rb/sssecrets) [![RubyDoc](https://img.shields.io/static/v1?url=https%3A%2F%2Frubydoc.info%2Fgems%2Fsssecrets&label=RubyDoc&message=sssecrets&color=informational)](https://rubydoc.info/gems/sssecrets) [![Build](https://github.com/chtzvt/sssecrets/actions/workflows/main.yml/badge.svg)](https://github.com/chtzvt/sssecrets/actions/workflows/main.yml) [![Publish](https://github.com/chtzvt/sssecrets/actions/workflows/release.yml/badge.svg)](https://github.com/chtzvt/sssecrets/actions/workflows/release.yml)

Sssecrets is a reusable implementation of GitHub's structured secret token format. You can learn more about GitHub's design process and the properties of their API token format on the [GitHub blog](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/).

## Why Structured Secrets?
Welcome to sssecrets: **S**imple **S**tructured **Secrets**. Sssecrets is a library for generating secrets (like API tokens, etc) in line with best practices.

If you're a developer and your application issues some kind of access tokens (API keys, PATs, etc), it's important to format these in a way that both identifies the string as a secret token and provides insight into its permissions. Even better if you provide example (dummy) tokens and regexes for them in your documentation!
Sssecrets is a reusable implementation of GitHub's [API token format](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/) (which is also used by [NPM](https://github.blog/2021-09-23-announcing-npms-new-access-token-format/)), and it's designed to make it simple for developers to issue secure secret tokens that are easy to detect when leaked.

You can learn more about GitHub's design process and the properties of this API token format on the [GitHub blog](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/).

## Why Structured Secrets?

If you're a developer and your application issues some kind of access tokens (API keys, PATs, etc), it's important to format these in a way that both identifies the string as a secret token and provides insight into its permissions. For bonus points, you should also provide example (dummy) tokens and regexes for them in your documentation.

Simple Structured Secrets help solve this problem: They're a compact format with properties that are optimized for detection with static analysis tools. That makes it possible to automatically detect when secrets are leaked in a codebase using features like [GitHub Secret Scanning](https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning) or GitLab Secret Detection.

Expand All @@ -22,14 +27,20 @@ While random, strings in this format are used in many places for non-sensitive p

Structured secrets have three parts:

- A prefix (defined by you),
- 30 characters of randomness,
- A 6 character checksum.
- A prefix (2-10 characters, defined by you)
- 30 characters of randomness
- A 6 character checksum

That's it!

That's it!
Here's the format:

`[prefix]_[randomness][checksum]`

An example Sssecret, with an `org` of `t` and a `type` of `k`, looks like this:

`tk_GNrRoBa1p9nuwm7XrWkrhYUNQ7edOw4GUp8I`

### Prefix

Token prefixes are a simple and effective method to make tokens identifiable. [Slack](https://api.slack.com/authentication/token-types), [Stripe](https://stripe.com/docs/api/authentication), [GitHub](https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/#identifiable-prefixes), and others have adopted this approach to great effect.
Expand All @@ -52,6 +63,8 @@ The token checksum can be used as a first-pass validity check. Using these check

_Note that this library can only check whether a given token is in the correct form and has a valid checksum. To fully determine whether a given token is active, you'll still need to implement your own logic for checking the validity of tokens you've issued._

_Another note: Because Sssecrets uses the same format as GitHub tokens, you can also perform offline validation of GitHub-issued secrets with `SimpleStructuredSecrets#validate`._

## Installation

Add this gem to your application's Gemfile:
Expand Down

0 comments on commit 16351aa

Please sign in to comment.