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

Improve error message when using self-signed certificate #119

Merged
merged 1 commit into from
Mar 29, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [8.0.6] - 2023-03-24

### Fixed
- Improved error message when using self-signed certificates
szh marked this conversation as resolved.
Show resolved Hide resolved
[cyberark/conjur-cli-go#119](https://github.com/cyberark/conjur-cli-go/pull/119)

## [8.0.5] - 2023-03-24

### Changed
Expand Down
4 changes: 2 additions & 2 deletions ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ services:
proxy:
image: nginx:1.13.6-alpine
volumes:
- ../conf/:/etc/nginx/conf.d/:ro
- ../conf/tls/:/etc/nginx/tls/:ro
- ./conf/:/etc/nginx/conf.d/:ro
- ./conf/tls/:/etc/nginx/tls/:ro
Comment on lines -26 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm this is to capture the idea that this docker-compose environment is only ever run with the working directory set to where the docker-compose.yml file is ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. This is used in the CI script and this path was incorrect to begin with from what I can tell. I only realized it when I tried to use the proxy service in the course of testing.

depends_on:
- conjur
restart: on-failure
Expand Down
13 changes: 13 additions & 0 deletions cmd/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ func TestIntegration(t *testing.T) {
assert.Contains(t, stdErr, "Must specify an Account")
})

t.Run("init with self-signed cert", func(t *testing.T) {
stdOut, stdErr, err = conjurCLI.Run("init", "-a", account, "-u", "https://proxy", "--force-netrc", "--force")
assert.Error(t, err)
assert.Equal(t, "", stdOut)
assert.Contains(t, stdErr, "Unable to retrieve and validate certificate")
assert.Contains(t, stdErr, "re-run the init command with the `--self-signed` flag")

stdOut, stdErr, err = conjurCLI.Run("init", "-a", account, "-u", "https://proxy", "--force-netrc", "--force", "--self-signed")
assert.NotContains(t, stdErr, "Unable to retrieve and validate certificate")
assert.Contains(t, stdOut, "The server's certificate fingerprint is")
assert.Contains(t, stdErr, selfSignedWarning)
})

t.Run("init", func(t *testing.T) {
stdOut, stdErr, err = conjurCLI.Run("init", "-a", account, "-u", "http://conjur", "-i", "--force-netrc", "--force")
assert.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions cmd/integration/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const pathToBinary = "conjur"

const insecureModeWarning = "Warning: Running the command with '--insecure' makes your system vulnerable to security attacks\n" +
"If you prefer to communicate with the server securely you must reinitialize the client in secure mode.\n"
const selfSignedWarning = "Warning: Using self-signed certificates is not recommended and could lead to exposure of sensitive data\n"

func newConjurCLI(homeDir string) *conjurCLI {
return &conjurCLI{
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"
"net/url"
"os"
Expand Down Expand Up @@ -199,7 +200,11 @@ func fetchCertIfNeeded(config *conjurapi.Config, cmdFlagVals initCmdFlagValues,

cert, err := utils.GetServerCert(url.Host, cmdFlagVals.selfSigned)
if err != nil {
return fmt.Errorf("Unable to retrieve certificate from %s: %s", url.Host, err)
errStr := fmt.Sprintf("Unable to retrieve and validate certificate from %s: %s", url.Host, err)
if !cmdFlagVals.selfSigned {
errStr += "\nIf you're attempting to use a self-signed certificate, re-run the init command with the `--self-signed` flag\n"
}
return errors.New(errStr)
}

// Prompt user to accept certificate
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@ appliance_url: http://host
name: "fails if can't retrieve server certificate",
args: []string{"init", "-u=https://nohost.example.com", "-a=test-account"},
assert: func(t *testing.T, conjurrcInTmpDir string, stdout string, stderr string, err error) {
assert.Contains(t, stderr, "Unable to retrieve certificate")
assert.Contains(t, stderr, "Unable to retrieve and validate certificate")
assertFetchCertFailed(t, conjurrcInTmpDir)
},
},
{
name: "fails for self-signed certificate",
args: []string{"init", "-u=https://self-signed.badssl.com", "-a=test-account"},
assert: func(t *testing.T, conjurrcInTmpDir string, stdout string, stderr string, err error) {
assert.Contains(t, stderr, "Unable to retrieve certificate")
assert.Contains(t, stderr, "Unable to retrieve and validate certificate")
assert.Contains(t, stderr, "If you're attempting to use a self-signed certificate, re-run the init command with the `--self-signed` flag")
assertFetchCertFailed(t, conjurrcInTmpDir)
},
},
Expand Down