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

Fix #52 conjur logon fail #54

Merged
merged 7 commits into from
Jan 27, 2021
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
6 changes: 3 additions & 3 deletions cmd/conjur.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ var conjurLogonCmd = &cobra.Command{
log.Fatalf("%s\n", err)
}

netrcPath := fmt.Sprintf("%s/.netrc", homeDir)
netrcPath := conjur.GetNetRcPath(homeDir)

// certPath remains empty if not using self-signed-cert
certPath := ""
if InsecureTLS {
certPath = fmt.Sprintf("%s/conjur-%s.pem", homeDir, Account)
certPath = conjur.GetConjurPemPath(homeDir, Account)
}

err = conjur.CreateConjurRc(Account, BaseURL, InsecureTLS)
Expand Down Expand Up @@ -434,7 +434,7 @@ func init() {
// list
conjurListResourcesCmd.Flags().StringVarP(&Kind, "kind", "k", "", "Narrows results to only resources of that kind")
conjurListResourcesCmd.Flags().StringVarP(&Search, "search", "s", "", "Narrows results to those pertaining to the search query")
conjurListResourcesCmd.Flags().IntVarP(&Limit, "limit", "l", 10, "Maximum number of returned resource. Default is 10")
conjurListResourcesCmd.Flags().IntVarP(&Limit, "limit", "l", 25, "Maximum number of returned resource. Default is 10")
conjurListResourcesCmd.Flags().IntVarP(&Offset, "offset", "o", 0, "Index to start returning results from for pagination")
conjurListResourcesCmd.Flags().BoolVarP(&InspectResources, "inspect", "i", false, "Show full object information")

Expand Down
11 changes: 9 additions & 2 deletions pkg/cybr/conjur/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ import (
"fmt"
"io"
"net/http"
"path/filepath"

"github.com/cyberark/conjur-api-go/conjurapi"
"github.com/cyberark/conjur-api-go/conjurapi/authn"
)

// GetNetRcPath returns path to the ~/.netrc file os-agnostic
func GetNetRcPath(homeDir string) string {
return filepath.FromSlash(fmt.Sprintf("%s/.netrc", homeDir))
}

// GetConjurClient create conjur client and login pair for ~/.conjurrc and ~/.netrc
func GetConjurClient() (*conjurapi.Client, *authn.LoginPair, error) {
homeDir, err := GetHomeDirectory()
if err != nil {
return nil, nil, fmt.Errorf("%s", err)
}

netrcPath := fmt.Sprintf("%s/.netrc", homeDir)
conjurrcPath := fmt.Sprintf("%s/.conjurrc", homeDir)
netrcPath := GetNetRcPath(homeDir)
conjurrcPath := GetConjurRcPath(homeDir)

account := GetAccountFromConjurRc(conjurrcPath)
baseURL := GetURLFromConjurRc(conjurrcPath)
certPath := GetCertFromConjurRc(conjurrcPath)
Expand Down
16 changes: 13 additions & 3 deletions pkg/cybr/conjur/conjurrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"os/user"
"path/filepath"
"strings"
)

Expand All @@ -19,6 +20,16 @@ appliance_url: {{ APPLIANCE_URL }}
cert_file: "{{ CERT_FILE }}"
`

// GetConjurRcPath returns path to the ~/.conjurrc file os-agnostic
func GetConjurRcPath(homeDir string) string {
return filepath.FromSlash(fmt.Sprintf("%s/.conjurrc", homeDir))
}

// GetConjurPemPath returns path to the ~/conjur-<account>.pem file os-agnostic
func GetConjurPemPath(homeDir string, account string) string {
return filepath.FromSlash(fmt.Sprintf("%s/conjur-%s.pem", homeDir, account))
}

func getPem(url string) (string, error) {
conf := &tls.Config{
InsecureSkipVerify: true,
Expand Down Expand Up @@ -154,16 +165,15 @@ func CreateConjurRc(account string, url string, selfSignedCert bool) error {

certFileName := ""
if selfSignedCert {
// create the ~/conjur-<accountName>.pem
certFileName = fmt.Sprintf("%s/conjur-%s.pem", homeDir, account)
certFileName = GetConjurPemPath(homeDir, account)
err = createConjurCert(certFileName, url)
if err != nil {
return err
}
}

// create the ~/.conjurrc file
conjurrcFileName := fmt.Sprintf("%s/.conjurrc", homeDir)
conjurrcFileName := GetConjurRcPath(homeDir)
err = createConjurRcFile(account, url, certFileName, conjurrcFileName)

return err
Expand Down