Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decouple certs from ssl #568

Merged
merged 7 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions api/controllers/certificates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package controllers

import (
"net/http"
"sort"
"strings"

"github.com/convox/rack/api/httperr"
"github.com/convox/rack/api/provider"
"github.com/gorilla/mux"
)

func CertificateCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
pub := r.FormValue("public")
key := r.FormValue("private")
chain := r.FormValue("chain")

cert, err := provider.CertificateCreate(pub, key, chain)

if err != nil {
return httperr.Server(err)
}

return RenderJson(rw, cert)
}

func CertificateDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
id := mux.Vars(r)["id"]

err := provider.CertificateDelete(id)

if err != nil {
return httperr.Server(err)
}

return RenderSuccess(rw)
}

func CertificateGenerate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
domains := strings.Split(r.FormValue("domains"), ",")

cert, err := provider.CertificateGenerate(domains)

if err != nil {
return httperr.Server(err)
}

return RenderJson(rw, cert)
}

func CertificateList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
certs, err := provider.CertificateList()

if err != nil {
return httperr.Server(err)
}

sort.Sort(certs)

return RenderJson(rw, certs)
}
4 changes: 4 additions & 0 deletions api/controllers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func NewRouter() (router *mux.Router) {
router.HandleFunc("/apps/{app}/ssl", api("ssl.list", SSLList)).Methods("GET")
router.HandleFunc("/apps/{app}/ssl/{process}/{port}", api("ssl.update", SSLUpdate)).Methods("PUT")
router.HandleFunc("/auth", api("auth", Auth)).Methods("GET")
router.HandleFunc("/certificates", api("certificate.list", CertificateList)).Methods("GET")
router.HandleFunc("/certificates", api("certificate.create", CertificateCreate)).Methods("POST")
router.HandleFunc("/certificates/generate", api("certificate.generate", CertificateGenerate)).Methods("POST")
router.HandleFunc("/certificates/{id}", api("certificate.delete", CertificateDelete)).Methods("DELETE")
router.HandleFunc("/index/diff", api("index.diff", IndexDiff)).Methods("POST")
router.HandleFunc("/index/file/{hash}", api("index.upload", IndexUpload)).Methods("POST")
router.HandleFunc("/instances", api("instances.get", InstancesList)).Methods("GET")
Expand Down
16 changes: 2 additions & 14 deletions api/controllers/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"net/http"
"strconv"
"strings"

"github.com/convox/rack/api/httperr"
"github.com/convox/rack/api/models"
Expand Down Expand Up @@ -31,10 +30,7 @@ func SSLUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
a := vars["app"]
process := vars["process"]
port := vars["port"]
arn := GetForm(r, "arn")
chain := GetForm(r, "chain")
body := GetForm(r, "body")
key := GetForm(r, "key")
id := GetForm(r, "id")

if process == "" {
return httperr.Errorf(403, "must specify a process")
Expand All @@ -46,11 +42,7 @@ func SSLUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
return httperr.Errorf(403, "port must be numeric")
}

if (arn != "") && !validateARNFormat(arn) {
return httperr.Errorf(403, "arn must follow the AWS ARN format")
}

ssl, err := models.UpdateSSL(a, process, portn, arn, body, key, chain)
ssl, err := models.UpdateSSL(a, process, portn, id)

if awsError(err) == "ValidationError" {
return httperr.Errorf(404, "%s", err)
Expand All @@ -62,7 +54,3 @@ func SSLUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {

return RenderJson(rw, ssl)
}

func validateARNFormat(arn string) bool {
return strings.HasPrefix(strings.ToLower(arn), "arn:")
}
5 changes: 5 additions & 0 deletions api/dist/kernel.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"Condition": "Development",
"Value": { "Fn::If": [ "Autoscale", "true", "false" ] }
},
"AwsAccount": {
"Condition": "Development",
"Value": { "Ref": "AWS::AccountId" }
},
"AwsRegion": {
"Condition": "Development",
"Value": { "Ref": "AWS::Region" }
Expand Down Expand Up @@ -1397,6 +1401,7 @@
"Command": "api/bin/web",
"CPU": "128",
"Environment": {
"AWS_ACCOUNT": { "Ref": "AWS::AccountId" },
"AWS_REGION": { "Ref": "AWS::Region" },
"AWS_ACCESS": { "Ref": "KernelAccess" },
"AWS_SECRET": { "Fn::GetAtt": [ "KernelAccess", "SecretAccessKey" ] },
Expand Down
82 changes: 82 additions & 0 deletions api/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,79 @@ paths:
description: invalid password
schema:
type: string
/certificates:
get:
description: List certificates
responses:
200:
description: certificate list
schema:
type: array
items:
$ref: '#/definitions/certificate'
post:
description: Upload a certificate
parameters:
- name: public
description: public key
type: string
in: formData
required: true
- name: private
description: private key
type: string
in: formData
required: true
- name: chain
description: intermediate chain
type: string
in: formData
required: false
responses:
200:
description: certificate
schema:
$ref: '#/definitions/certificate'
403:
description: invalid certificate
schema:
$ref: '#/definitions/error'
/certificates/generate:
post:
description: Request a certificate
parameters:
- name: domains
description: public key
type: array
items:
type: string
responses:
200:
description: certificate
schema:
$ref: '#/definitions/certificate'
403:
description: invalid domains
schema:
$ref: '#/definitions/error'
/certificates/{id}:
delete:
description: Remove a certificate
parameters:
- name: id
description: certificate id
type: string
in: path
required: true
responses:
200:
description: success
schema:
$ref: '#/definitions/success'
404:
description: not found
schema:
$ref: '#/definitions/error'
/instances:
get:
description: List instances.
Expand Down Expand Up @@ -825,6 +898,13 @@ definitions:
type: integer
process-width:
type: integer
certificate:
domain:
type: string
expiration:
type: date
id:
type: string
error:
properties:
error:
Expand Down Expand Up @@ -915,6 +995,8 @@ definitions:
type: string
ssl:
properties:
certificate:
type: string
domain:
type: string
expiration:
Expand Down
5 changes: 5 additions & 0 deletions api/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/acm"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudwatch"
Expand Down Expand Up @@ -58,6 +59,10 @@ func awsConfig() *aws.Config {
return config
}

func ACM() *acm.ACM {
return acm.New(session.New(), awsConfig())
}

func AutoScaling() *autoscaling.AutoScaling {
return autoscaling.New(session.New(), awsConfig())
}
Expand Down
3 changes: 1 addition & 2 deletions api/models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ func (r *Release) Promote() error {
switch app.Parameters[protoParam] {
case "https", "tls":
if app.Parameters[certParam] == "" {
timestamp := time.Now().Format("20060102150405")
name := fmt.Sprintf("%s%s%s-%s", UpperName(app.StackName()), UpperName(entry.Name), mapping.Balancer, timestamp)
name := fmt.Sprintf("cert-%d", time.Now().Unix())

body, key, err := GenerateSelfSignedCertificate("*.*.elb.amazonaws.com")

Expand Down
Loading