Skip to content

Instantly share code, notes, and snippets.

package auth
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"time"
@paultyng
paultyng / keybase.md
Created April 1, 2020 20:46
Keybase proof

Keybase proof

I hereby claim:

  • I am paultyng on github.
  • I am paultyng (https://keybase.io/paultyng) on keybase.
  • I have a public key whose fingerprint is 5C7F DE00 84B8 A02C 1571 545F 7E44 81B7 24D4 4C66

To claim this, I am signing this object:

@paultyng
paultyng / aws_presign.go
Created March 24, 2020 14:52
Create AWS IoT MQTT Presign URL in Go
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
"net/url"
"strings"
"time"
@paultyng
paultyng / cmd.sh
Last active September 10, 2018 09:21
Gopkg.lock to vendor.json - dep to govendor
# tomljson from https://github.com/pelletier/go-toml
tomljson Gopkg.lock \
| jq '{ comment: "", ignore: "test", package: [.projects[] | . as $project | .packages[] | { path: ($project.name + if . == "." then "" else ("/" + .) end), revision: $project.revision } + if $project.version then { version: $project.version, versionExact: $project.version } else {} end], rootPath: "github.com/..." }'
@paultyng
paultyng / install_awscli.cmd
Created March 17, 2016 13:31
Install AWSCLI via Powershell
Invoke-WebRequest -Uri https://s3.amazonaws.com/aws-cli/AWSCLI64.msi -Outfile Z:\AWSCLI64.msi
#!/bin/bash
remote="${1:-origin}"
echo "Using remote $remote"
branches="$(git ls-remote --heads $remote | awk '{print $2}' | awk -F'/' '{print $3}' | grep '^v' | sort | uniq)"
echo "$branches" | while read branch; do
echo "Branch: $branch"

Better SSH Authorized Keys Management

A seemingly common problem that people encounter is how to handle all of your users authorized_keys file.

People struggle over management, ensuring that users only have specific keys in the authorized_keys file or even a method for expiring keys. A centralized key management system could help provide all of this functionality with a little scripting.

One piece of functionality overlooked in OpenSSH is the AuthorizedKeysCommand configuration keyword. This configuration allows you to specify a command that will run during login to retrieve a users public key file from a remote source and perform validation just as if the authorized_keys file was local.

Here is an example directory structure for a set of users with SSH public keys that can be shared out via a web server:

@paultyng
paultyng / password.tf
Last active November 30, 2017 22:52
Terraform Random Password Module
variable "length" {
default = "20"
}
resource "random_id" "password" {
byte_length = "${var.length * 3 / 4}"
}
output "password" {
value = "${random_id.password.b64}"
@paultyng
paultyng / document.js
Last active June 15, 2017 12:23
Algolia - Material Document
{
"asset": {
"url": "https://underarmour.scene7.com/is/image/Underarmour//1299081-025_LA?$size=279,360&hei=400&wid=310&$extend=0"
},
"catalogs": [
1824,
1825,
1897,
1898,
1899,
@paultyng
paultyng / jwtRS256.sh
Created April 17, 2017 19:27 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub