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

Fixed date format in revocation request #33

Merged
merged 61 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0754030
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Aug 17, 2023
8740671
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
3cfd9d4
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
e203557
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
4a0f1e7
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
e64a904
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
10a0e6c
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
57bc510
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
541731d
feat(ci): Adding CI to build different architectures of the plugin.
spbsoluble Jan 19, 2024
580f15c
fix(ci): Remove release.yml
spbsoluble Jan 19, 2024
ccd12a4
ignoring binaries
joevanwanzeeleKF Mar 21, 2024
218d688
cleaned up artifacts, added role explanation to README, fixed domain …
joevanwanzeeleKF Mar 21, 2024
0fb49c3
cleanup
joevanwanzeeleKF Mar 21, 2024
080f274
Updated README for clarity on role functionality
joevanwanzeeleKF Mar 22, 2024
9486109
Update .goreleaser.yml to create sha256 for binary
joevanwanzeeleKF Mar 25, 2024
84a3bde
Adding CHANGELOG and readme_source to facilitate builds via goreleaser.
joevanwanzeeleKF Mar 25, 2024
a10aee4
Merge branch 'fix_ci' of https://github.com/Keyfactor/hashicorp-vault…
joevanwanzeeleKF Mar 25, 2024
d292940
Merge branch 'role-domain-validation' of https://github.com/Keyfactor…
joevanwanzeeleKF Mar 25, 2024
b162937
Update generated README
Mar 25, 2024
1de04c2
removed "split" property until goreleaser is updated to 1.25+
joevanwanzeeleKF Mar 25, 2024
67205a8
Merge branch 'role-domain-validation' of https://github.com/Keyfactor…
joevanwanzeeleKF Mar 25, 2024
92d506f
updated template name for checksums file
joevanwanzeeleKF Mar 25, 2024
66741b2
added license file, updated to generate checksum for binary only
joevanwanzeeleKF Mar 25, 2024
068ed18
updated goreleaser
joevanwanzeeleKF Mar 25, 2024
6445c5e
fix
joevanwanzeeleKF Mar 25, 2024
a9133c1
goreleaser mod
joevanwanzeeleKF Mar 25, 2024
ef9ab77
updating gorleaser to get checksum for binary
joevanwanzeeleKF Mar 26, 2024
1b56bbb
write checksums to BUILD_ARTIFACT_DIR
joevanwanzeeleKF Mar 26, 2024
609da3d
typo
joevanwanzeeleKF Mar 26, 2024
d6545b4
.Env
joevanwanzeeleKF Mar 26, 2024
e31a180
removed a set of curly braces
joevanwanzeeleKF Mar 26, 2024
e3f9f6b
updated output in extra_files
joevanwanzeeleKF Mar 26, 2024
8cfffd7
moving hook to post instead of pre
joevanwanzeeleKF Mar 28, 2024
fa3e5bd
github action
joevanwanzeeleKF Mar 28, 2024
ce82080
writing checksums to dist/
joevanwanzeeleKF Mar 28, 2024
12b87c4
adding the glob to extra files for binary checksums
joevanwanzeeleKF Mar 28, 2024
24f351f
added full path to checksums in glob property
joevanwanzeeleKF Mar 28, 2024
3fcb9e7
fixing format in checksums output
joevanwanzeeleKF Mar 28, 2024
bf3bd63
changed prop to .Target from .Goos and .Goarch
joevanwanzeeleKF Mar 28, 2024
24e60bb
quotation fix
joevanwanzeeleKF Mar 29, 2024
8eed114
fix formatting
joevanwanzeeleKF Mar 29, 2024
0fe2b0b
double quotes
joevanwanzeeleKF Mar 29, 2024
455d570
adding tabs for formatting
joevanwanzeeleKF Mar 29, 2024
1e2f6f7
splitting target value into os and arch
joevanwanzeeleKF Mar 29, 2024
5483193
formatting
joevanwanzeeleKF Mar 29, 2024
ccfdc89
inserting tabs for readability
joevanwanzeeleKF Apr 1, 2024
7dca349
giving up trying to insert tab
joevanwanzeeleKF Apr 1, 2024
20f81b1
attempting tab again
joevanwanzeeleKF Apr 1, 2024
56d3df4
format
joevanwanzeeleKF Apr 1, 2024
6ff5431
formatting
joevanwanzeeleKF Apr 1, 2024
3664064
format - works in fedora
joevanwanzeeleKF Apr 1, 2024
ddfa101
attempting to use other global vars
joevanwanzeeleKF Apr 1, 2024
114827d
formatting
joevanwanzeeleKF Apr 1, 2024
2bf92b2
format
joevanwanzeeleKF Apr 1, 2024
423f883
format
joevanwanzeeleKF Apr 1, 2024
a931b66
Fixed SANS validation. added check for at least one SANS == CN.
joevanwanzeeleKF Apr 2, 2024
b56696e
Merge branch 'checksum-build-action' into role-domain-validation
joevanwanzeeleKF Apr 2, 2024
a40fe5b
moved common validation to outside of loop
joevanwanzeeleKF Apr 2, 2024
8108aca
Merge branch 'role-domain-validation' of https://github.com/Keyfactor…
joevanwanzeeleKF Apr 2, 2024
25aa887
cleanup
joevanwanzeeleKF Apr 2, 2024
5ca1019
fixed time format causing an error during revocation
joevanwanzeeleKF Apr 10, 2024
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
14 changes: 12 additions & 2 deletions backend.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import (
Expand All @@ -6,6 +15,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
Expand Down Expand Up @@ -148,9 +158,9 @@ func (b *keyfactorBackend) submitCSR(ctx context.Context, req *logical.Request,
if res.StatusCode != 200 {
b.Logger().Error("CSR Enrollment failed: server returned" + fmt.Sprint(res.StatusCode))
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)
b.Logger().Error("Error response: " + string(body[:]))
return nil, "", fmt.Errorf("enrollment failed: server returned %d\n ", res.StatusCode)
return nil, "", fmt.Errorf("CSR Enrollment request failed with status code %d and error: "+string(body[:]), res.StatusCode)
}

// Read response and return certificate and key
Expand Down
8 changes: 8 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
__='
Copyright 2024 Keyfactor
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
and limitations under the License.
'
#!
/usr/local/go/bin/go build -o vault/plugins/keyfactor cmd/keyfactor/main.go
vault secrets disable keyfactor
Expand Down
9 changes: 9 additions & 0 deletions cert_util.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import (
Expand Down
9 changes: 9 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import (
Expand Down
9 changes: 9 additions & 0 deletions cmd/keyfactor/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package main

import (
Expand Down
9 changes: 9 additions & 0 deletions fields.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import "github.com/hashicorp/vault/sdk/framework"
Expand Down
9 changes: 9 additions & 0 deletions path_ca.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import (
Expand Down
67 changes: 52 additions & 15 deletions path_certs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import (
Expand All @@ -8,6 +17,7 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -126,6 +136,7 @@ func (b *keyfactorBackend) pathFetchCert(ctx context.Context, req *logical.Reque
// this is basically handled by setting contentType or not.
// Errors don't cause an immediate exit, because the raw
// paths still need to return raw output.

b.Logger().Debug("fetching cert, path = " + req.Path)

serial = data.Get("serial").(string)
Expand Down Expand Up @@ -331,7 +342,6 @@ func (b *keyfactorBackend) pathIssueSignCert(ctx context.Context, req *logical.R

// check the allowed domains for a match.
for _, v := range role.AllowedDomains {
b.Logger().Warn(v)
if strings.HasSuffix(cn.(string), v) { // if it has the suffix..
hasSuffix = true
if cn.(string) == v || role.AllowSubdomains { // and there is an exact match, or subdomains are allowed..
Expand All @@ -351,10 +361,38 @@ func (b *keyfactorBackend) pathIssueSignCert(ctx context.Context, req *logical.R
return nil, err_resp
}

// check the provided DNS sans against allowed domains
var cnMatch = false
b.Logger().Trace("checking dns sans" + dns_sans[0] + ", ...")
for u := range dns_sans {
if !strings.Contains(dns_sans[u], role.AllowedBaseDomain) || strings.Contains(dns_sans[u], role.AllowedBaseDomain) && !role.AllowSubdomains {
return nil, fmt.Errorf("Subject Alternative Name " + dns_sans[u] + " not allowed for provided role")
valid = false
hasSuffix = false
cnMatch = cnMatch || dns_sans[u] == cn.(string) // check to make sure at least one of the dns_sans match the cn
b.Logger().Trace("checking SANs")
for _, v := range role.AllowedDomains {
if strings.HasSuffix(dns_sans[u], v) { // if it has the suffix..
hasSuffix = true
if dns_sans[u] == v || role.AllowSubdomains { // and there is an exact match, or subdomains are allowed..
valid = true // then it is valid
}
}
}
if !valid {
err_resp = fmt.Errorf("Subject Alternative Name " + dns_sans[u] + " not allowed for provided role")
}
if !valid && hasSuffix {
err_resp = fmt.Errorf("sub-domains not allowed for role")
}
}

b.Logger().Trace("cnMatch = " + strconv.FormatBool(cnMatch))

if !cnMatch {
err_resp = fmt.Errorf("at least one DNS SAN is required to match the supplied Common Name for RFC 2818 compliance")
}

if err_resp != nil {
return nil, err_resp
}

//generate and submit CSR
Expand All @@ -381,9 +419,6 @@ func (b *keyfactorBackend) pathIssueSignCert(ctx context.Context, req *logical.R
}

func (b *keyfactorBackend) pathRevokeCert(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
//path := data.Get("path").(string)
//b.Logger().Debug("path = " + path)

serial := data.Get("serial").(string)
b.Logger().Debug("serial = " + serial)

Expand Down Expand Up @@ -451,8 +486,8 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
"Comment": "%s",
"EffectiveDate": "%s"},
"CollectionId": 0
}`, keyfactorId, "via HashiCorp Vault", time.Now().UTC().String())
//b.Logger().Debug("Sending revocation request. payload = " + payload)
}`, keyfactorId, "via HashiCorp Vault", time.Now().Format(time.RFC3339))
b.Logger().Debug("Sending revocation request. payload = " + payload)
httpReq, _ := http.NewRequest("POST", url, strings.NewReader(payload))

httpReq.Header.Add("x-keyfactor-requested-with", "APIClient")
Expand All @@ -464,10 +499,13 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
b.Logger().Error("Revoke failed: {{err}}", err)
return nil, err
}
if res.StatusCode != 204 {
r, _ := io.ReadAll(res.Body)
r, _ := io.ReadAll(res.Body)

b.Logger().Debug("response received. Status code " + fmt.Sprint(res.StatusCode) + " response body: \n " + string(r[:]))
if res.StatusCode != 204 && res.StatusCode != 200 {
// r, _ := io.ReadAll(res.Body)
b.Logger().Info("revocation failed: server returned" + fmt.Sprint(res.StatusCode))
b.Logger().Info("error response = " + fmt.Sprint(r))
b.Logger().Info("error response = " + string(r[:]))
return nil, fmt.Errorf("revocation failed: server returned %s\n ", res.Status)
}

Expand Down Expand Up @@ -514,8 +552,8 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
}
return logical.ErrorResponse(fmt.Sprintf("certificate with serial %s not found", serial)), nil
}
b.Logger().Info("certEntry key = " + certEntry.Key)
b.Logger().Info("certEntry value = " + string(certEntry.Value))
b.Logger().Debug("certEntry key = " + certEntry.Key)
b.Logger().Debug("certEntry value = " + string(certEntry.Value))

currTime := time.Now()
revInfo.CertificateBytes = certEntry.Value
Expand All @@ -531,7 +569,6 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
if err != nil {
return nil, fmt.Errorf("error saving revoked certificate to new location")
}

}

resp := &logical.Response{
Expand All @@ -540,7 +577,7 @@ func revokeCert(ctx context.Context, b *keyfactorBackend, req *logical.Request,
},
}
if !revInfo.RevocationTimeUTC.IsZero() {
resp.Data["revocation_time_rfc3339"] = revInfo.RevocationTimeUTC.Format(time.RFC3339Nano)
resp.Data["revocation_time_rfc3339"] = revInfo.RevocationTimeUTC.Format(time.RFC3339)
}
return resp, nil
}
Expand Down
20 changes: 11 additions & 9 deletions path_config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import (
"context"
"errors"
"fmt"

"github.com/hashicorp/vault/sdk/framework"
Expand Down Expand Up @@ -153,18 +161,12 @@ func (b *keyfactorBackend) pathConfigWrite(ctx context.Context, req *logical.Req
return nil, err
}

createOperation := false // always update. not necessary to require all fields added simultaneously

if existingConfig == nil {
existingConfig = newConfig
}

createOperation := (req.Operation == logical.CreateOperation)

if newConfig == nil {
if !createOperation {
return nil, errors.New("config not found during update operation")
}
}

if username, ok := data.GetOk("username"); ok {
existingConfig.Username = username.(string)
} else if !ok && createOperation {
Expand Down
9 changes: 9 additions & 0 deletions path_revoke.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

// import (
Expand Down
9 changes: 9 additions & 0 deletions path_roles.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Keyfactor
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

package keyfactor

import (
Expand Down
Loading