Skip to content

Commit

Permalink
chore: change name to notary (#65)
Browse files Browse the repository at this point in the history
Signed-off-by: guillaume <[email protected]>
Co-authored-by: Kayra <[email protected]>
  • Loading branch information
gruyaume and kayra1 committed Sep 9, 2024
1 parent 46be692 commit 5aa11aa
Show file tree
Hide file tree
Showing 25 changed files with 99 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build GoCert
name: Build Notary

on:
workflow_call:
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/build-rock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ jobs:

- name: Import the image to Docker registry
run: |
sudo rockcraft.skopeo --insecure-policy copy oci-archive:${{ steps.rockcraft.outputs.rock }} docker-daemon:gocert:latest
sudo rockcraft.skopeo --insecure-policy copy oci-archive:${{ steps.rockcraft.outputs.rock }} docker-daemon:notary:latest
- name: Create files required by GoCert
- name: Create files required by Notary
run: |
printf 'key_path: "/etc/gocert/config/key.pem"\ncert_path: "/etc/gocert/config/cert.pem"\ndb_path: "/var/lib/gocert/database/certs.db"\nport: 3000\npebble_notifications: true\n' > config.yaml
printf 'key_path: "/etc/notary/config/key.pem"\ncert_path: "/etc/notary/config/cert.pem"\ndb_path: "/var/lib/notary/database/certs.db"\nport: 3000\npebble_notifications: true\n' > config.yaml
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 1 -out cert.pem -subj "/CN=githubaction.example"
- name: Run the image
run: |
docker run -d -p 3000:3000 --name gocert gocert:latest
docker run -d -p 3000:3000 --name notary notary:latest
- name: Load config
run: |
docker exec gocert /usr/bin/pebble mkdir -p /etc/gocert/config
docker exec gocert /usr/bin/pebble mkdir -p /var/lib/gocert/database
docker cp key.pem gocert:/etc/gocert/config/key.pem
docker cp cert.pem gocert:/etc/gocert/config/cert.pem
docker cp config.yaml gocert:/etc/gocert/config/config.yaml
docker restart gocert
- name: Check if GoCert frontend is loaded
docker exec notary /usr/bin/pebble mkdir -p /etc/notary/config
docker exec notary /usr/bin/pebble mkdir -p /var/lib/notary/database
docker cp key.pem notary:/etc/notary/config/key.pem
docker cp cert.pem notary:/etc/notary/config/cert.pem
docker cp config.yaml notary:/etc/notary/config/config.yaml
docker restart notary
- name: Check if Notary frontend is loaded
run: |
sleep 30
docker logs gocert
docker logs notary
curl -k https://localhost:3000/certificate_requests.html 2>&1 | grep "Certificate Requests"
- name: Test if pebble notify fires correctly
Expand Down Expand Up @@ -121,9 +121,9 @@ jobs:
jdzVA8yTI8cZ/RtRohp5H/s+j2tcdfB3Zt+wfS4nLxqN/kf7qv2VSdPbXyTyz/ft
btZkbfdL5A==
-----END CERTIFICATE-----' -H "Authorization: Bearer $ADMIN_TOKEN" 'https://localhost:3000/api/v1/certificate_requests/1/certificate'
docker exec gocert /usr/bin/pebble notices
docker exec gocert /usr/bin/pebble notices | grep gocert\\.com/certificate/update
docker exec gocert /usr/bin/pebble notice 3
docker exec notary /usr/bin/pebble notices
docker exec notary /usr/bin/pebble notices | grep notary\\.com/certificate/update
docker exec notary /usr/bin/pebble notice 3
- uses: actions/upload-artifact@v4
if: steps.test_notify.outcome == 'success'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
uses: ./.github/workflows/test-frontend.yaml
build-nextjs:
uses: ./.github/workflows/build-frontend.yaml
unit-test-gocert:
unit-test-notary:
needs: [build-nextjs]
uses: ./.github/workflows/test-gocert.yaml
uses: ./.github/workflows/test-notary.yaml
go-vet:
needs: [build-nextjs]
uses: ./.github/workflows/go-vet.yaml
go-lint:
needs: [build-nextjs]
uses: ./.github/workflows/go-lint.yaml
build-gocert:
build-notary:
needs: [build-nextjs]
uses: ./.github/workflows/build-gocert.yaml
uses: ./.github/workflows/build-notary.yaml
rock-build:
needs: [build-gocert, unit-test-gocert, go-vet, go-lint]
needs: [build-notary, unit-test-notary, go-vet, go-lint]
uses: ./.github/workflows/build-rock.yaml
rock-scan:
if: github.ref_name == 'main'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Test GoCert
name: Unit Test Notary

on:
workflow_call:
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You can build and run the program by following these steps:
4. Build the frontend: `npm i --prefix ui && npm run build --prefix ui`
5. Install the project: `go install ./...`
6. Create a `config.yaml` file as described in README.md
7. Run the project: `gocert -config config.yaml`
7. Run the project: `notary -config config.yaml`

Commands assume you're running them from the top level git repo directory

Expand Down Expand Up @@ -46,6 +46,6 @@ You can create the container and import it into docker by running:
```bash
rockcraft pack -v
version=$(yq '.version' rockcraft.yaml)
sudo rockcraft.skopeo --insecure-policy copy oci-archive:gocert_${version}_amd64.rock docker-daemon:gocert:${version}
docker run gocert:${version}
sudo rockcraft.skopeo --insecure-policy copy oci-archive:notary_${version}_amd64.rock docker-daemon:notary:${version}
docker run notary:${version}
```
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# gocert
# notary

GoCert is a certificate management tool.
Notary is a certificate management tool.

## Requirements

GoCert requires 3 files to operate:
Notary requires 3 files to operate:
* A private key
* A TLS certificate with that private key
* A YAML config file with the required parameters
Expand All @@ -14,24 +14,24 @@ You can generate the cert and the associated key by running:
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 1 -out cert.pem -subj "/CN=example.com"
```

GoCert does not support insecure http connections.
Notary does not support insecure http connections.

### Config File
The config file requires the following parameters:
| Key | Type | Description |
|----------------------|---------|----------|
| key_path | string | path to the private key for enabling HTTPS connections |
| cert_path | string | path to a PEM formatted certificate for enabling HTTPS connections |
| db_path | string | path to a sqlite database file. If the file does not exist GoCert will attempt to create it. |
| port | integer (0-65535) | port number on which GoCert will listen for all incoming API and frontend connections. |
| pebble_notifications | boolean | Allow GoCert to send pebble notices on certificate events (create, update, delete). Pebble needs to be running on the same system as GoCert. Read more about Pebble Notices [here](https://github.com/canonical/pebble?tab=readme-ov-file#notices). |
| Key | Type | Description |
| -------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| key_path | string | path to the private key for enabling HTTPS connections |
| cert_path | string | path to a PEM formatted certificate for enabling HTTPS connections |
| db_path | string | path to a sqlite database file. If the file does not exist Notary will attempt to create it. |
| port | integer (0-65535) | port number on which Notary will listen for all incoming API and frontend connections. |
| pebble_notifications | boolean | Allow Notary to send pebble notices on certificate events (create, update, delete). Pebble needs to be running on the same system as Notary. Read more about Pebble Notices [here](https://github.com/canonical/pebble?tab=readme-ov-file#notices). |

An example config file may look like:

```yaml
key_path: "/etc/gocert/config/key.pem"
cert_path: "/etc/gocert/config/cert.pem"
db_path: "/var/lib/gocert/database/certs.db"
key_path: "/etc/notary/config/key.pem"
cert_path: "/etc/notary/config/cert.pem"
db_path: "/var/lib/notary/database/certs.db"
port: 3000
pebble_notifications: true
```
Expand All @@ -42,23 +42,23 @@ pebble_notifications: true
```bash
# Pull the OCI image from github and run it in docker
docker pull ghcr.io/canonical/gocert:latest
docker run -d --name gocert -p 3000:3000 ghcr.io/canonical/gocert:latest
docker pull ghcr.io/canonical/notary:latest
docker run -d --name notary -p 3000:3000 ghcr.io/canonical/notary:latest
# Push the 3 required files and restart the workload
docker exec gocert /usr/bin/pebble mkdir -p /etc/gocert/config
docker exec gocert /usr/bin/pebble mkdir -p /var/lib/gocert/database
docker cp key.pem gocert:/etc/gocert/config/key.pem
docker cp cert.pem gocert:/etc/gocert/config/cert.pem
docker cp config.yaml gocert:/etc/gocert/config/config.yaml
docker restart gocert
docker exec notary /usr/bin/pebble mkdir -p /etc/notary/config
docker exec notary /usr/bin/pebble mkdir -p /var/lib/notary/database
docker cp key.pem notary:/etc/notary/config/key.pem
docker cp cert.pem notary:/etc/notary/config/cert.pem
docker cp config.yaml notary:/etc/notary/config/config.yaml
docker restart notary
```

### From Source

go and npm CLI tools need to be installed in order to build gocert from source.
You will need to build the frontend first, and then install gocert with Go.
go and npm CLI tools need to be installed in order to build notary from source.
You will need to build the frontend first, and then install notary with Go.

```bash
npm install --prefix ui && npm run build --prefix ui && go install ./...
gocert -config ./config.yaml
notary -config ./config.yaml
```
4 changes: 2 additions & 2 deletions cmd/gocert/main.go → cmd/notary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"log"
"os"

server "github.com/canonical/gocert/internal/api"
"github.com/canonical/gocert/internal/config"
server "github.com/canonical/notary/internal/api"
"github.com/canonical/notary/internal/config"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions cmd/gocert/main_test.go → cmd/notary/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pebble_notices: false`
func TestMain(m *testing.M) {
cmd := exec.Command("go", "install", "./...")
if err := cmd.Run(); err != nil {
log.Fatalf("couldn't install the gocert CLI")
log.Fatalf("couldn't install the notary CLI")
}

testfolder, err := os.MkdirTemp("./", "configtest-")
Expand All @@ -131,7 +131,7 @@ func TestMain(m *testing.M) {
os.Exit(exitval)
}

func TestGoCertFail(t *testing.T) {
func TestNotaryFail(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
cases := []struct {
Expand All @@ -150,7 +150,7 @@ func TestGoCertFail(t *testing.T) {
t.Errorf("Failed writing config file")
}
flag.CommandLine = flag.NewFlagSet(tc.Name, flag.ExitOnError)
cmd := exec.Command("gocert", tc.Args...)
cmd := exec.Command("notary", tc.Args...)
stdout, _ := cmd.StdoutPipe()

if err := cmd.Start(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/canonical/gocert
module github.com/canonical/notary

go 1.22.1

Expand Down
20 changes: 10 additions & 10 deletions internal/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ import (
"strings"
"time"

"github.com/canonical/gocert/internal/certdb"
metrics "github.com/canonical/gocert/internal/metrics"
"github.com/canonical/gocert/ui"
"github.com/canonical/notary/internal/certdb"
metrics "github.com/canonical/notary/internal/metrics"
"github.com/canonical/notary/ui"
"github.com/golang-jwt/jwt"
"golang.org/x/crypto/bcrypt"
)

// NewGoCertRouter takes in an environment struct, passes it along to any handlers that will need
// NewNotaryRouter takes in an environment struct, passes it along to any handlers that will need
// access to it, and takes an http.Handler that will be used to handle metrics.
// then builds and returns it for a server to consume
func NewGoCertRouter(env *Environment) http.Handler {
func NewNotaryRouter(env *Environment) http.Handler {
apiV1Router := http.NewServeMux()
apiV1Router.HandleFunc("GET /certificate_requests", GetCertificateRequests(env))
apiV1Router.HandleFunc("POST /certificate_requests", PostCertificateRequest(env))
Expand Down Expand Up @@ -221,7 +221,7 @@ func PostCertificate(env *Environment) http.HandlerFunc {
}
insertIdStr := strconv.FormatInt(insertId, 10)
if env.SendPebbleNotifications {
err := SendPebbleNotification("gocert.com/certificate/update", insertIdStr)
err := SendPebbleNotification("notary.com/certificate/update", insertIdStr)
if err != nil {
log.Printf("pebble notify failed: %s. continuing silently.", err.Error())
}
Expand All @@ -247,7 +247,7 @@ func RejectCertificate(env *Environment) http.HandlerFunc {
}
insertIdStr := strconv.FormatInt(insertId, 10)
if env.SendPebbleNotifications {
err := SendPebbleNotification("gocert.com/certificate/update", insertIdStr)
err := SendPebbleNotification("notary.com/certificate/update", insertIdStr)
if err != nil {
log.Printf("pebble notify failed: %s. continuing silently.", err.Error())
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func DeleteCertificate(env *Environment) http.HandlerFunc {
}
insertIdStr := strconv.FormatInt(insertId, 10)
if env.SendPebbleNotifications {
err := SendPebbleNotification("gocert.com/certificate/update", insertIdStr)
err := SendPebbleNotification("notary.com/certificate/update", insertIdStr)
if err != nil {
log.Printf("pebble notify failed: %s. continuing silently.", err.Error())
}
Expand Down Expand Up @@ -600,7 +600,7 @@ func validatePassword(password string) bool {

// Helper function to generate a JWT
func generateJWT(id int, username string, jwtSecret []byte, permissions int) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwtGocertClaims{
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwtNotaryClaims{
ID: id,
Username: username,
Permissions: permissions,
Expand All @@ -616,7 +616,7 @@ func generateJWT(id int, username string, jwtSecret []byte, permissions int) (st
return tokenString, nil
}

type jwtGocertClaims struct {
type jwtNotaryClaims struct {
ID int `json:"id"`
Username string `json:"username"`
Permissions int `json:"permissions"`
Expand Down
16 changes: 8 additions & 8 deletions internal/api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"strings"
"testing"

server "github.com/canonical/gocert/internal/api"
"github.com/canonical/gocert/internal/certdb"
server "github.com/canonical/notary/internal/api"
"github.com/canonical/notary/internal/certdb"
"github.com/golang-jwt/jwt"
)

Expand Down Expand Up @@ -152,14 +152,14 @@ const (
notExistingUser = `{"username": "not_existing", "password": "user"}`
)

func TestGoCertCertificatesHandlers(t *testing.T) {
func TestNotaryCertificatesHandlers(t *testing.T) {
testdb, err := certdb.NewCertificateRequestsRepository(":memory:", "CertificateRequests")
if err != nil {
log.Fatalf("couldn't create test sqlite db: %s", err)
}
env := &server.Environment{}
env.DB = testdb
ts := httptest.NewTLSServer(server.NewGoCertRouter(env))
ts := httptest.NewTLSServer(server.NewNotaryRouter(env))
defer ts.Close()

client := ts.Client()
Expand Down Expand Up @@ -409,14 +409,14 @@ func TestGoCertCertificatesHandlers(t *testing.T) {

}

func TestGoCertUsersHandlers(t *testing.T) {
func TestNotaryUsersHandlers(t *testing.T) {
testdb, err := certdb.NewCertificateRequestsRepository(":memory:", "CertificateRequests")
if err != nil {
log.Fatalf("couldn't create test sqlite db: %s", err)
}
env := &server.Environment{}
env.DB = testdb
ts := httptest.NewTLSServer(server.NewGoCertRouter(env))
ts := httptest.NewTLSServer(server.NewNotaryRouter(env))
defer ts.Close()

client := ts.Client()
Expand Down Expand Up @@ -580,7 +580,7 @@ func TestLogin(t *testing.T) {
env := &server.Environment{}
env.DB = testdb
env.JWTSecret = []byte("secret")
ts := httptest.NewTLSServer(server.NewGoCertRouter(env))
ts := httptest.NewTLSServer(server.NewNotaryRouter(env))
defer ts.Close()

client := ts.Client()
Expand Down Expand Up @@ -694,7 +694,7 @@ func TestAuthorization(t *testing.T) {
env := &server.Environment{}
env.DB = testdb
env.JWTSecret = []byte("secret")
ts := httptest.NewTLSServer(server.NewGoCertRouter(env))
ts := httptest.NewTLSServer(server.NewNotaryRouter(env))
defer ts.Close()

client := ts.Client()
Expand Down
Loading

0 comments on commit 5aa11aa

Please sign in to comment.