Skip to content

Instantly share code, notes, and snippets.

@abohmeed
Last active June 1, 2020 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abohmeed/58b3f0e24e9d0d77e9b5041724068fe8 to your computer and use it in GitHub Desktop.
Save abohmeed/58b3f0e24e9d0d77e9b5041724068fe8 to your computer and use it in GitHub Desktop.
k8suser gists
key, err := rsa.GenerateKey(rand.Reader, 1024)
check("The following error occured while creating the RSA key", err)
keyDer := x509.MarshalPKCS1PrivateKey(key)
commonName := *usernamePtr
emailAddress := *emailPtr
org := strings.ToUpper(*orgazniationPtr)
orgUnit := strings.ToUpper(*orgUnitPtr)
city := strings.ToUpper(*cityPtr)
state := strings.ToUpper(*provincePtr)
country := strings.ToUpper(*countryPtr)
subject := pkix.Name{
CommonName: commonName,
Country: []string{country},
Locality: []string{city},
Organization: []string{org},
OrganizationalUnit: []string{orgUnit},
Province: []string{state},
}
asn1, err := asn1.Marshal(subject.ToRDNSequence())
check("The following error occured while creating the asn1 DNS sequence", err)
csrReq := x509.CertificateRequest{
RawSubject: asn1,
EmailAddresses: []string{emailAddress},
SignatureAlgorithm: x509.SHA256WithRSA,
}
bytes, err := x509.CreateCertificateRequest(rand.Reader, &csrReq, key)
check("The following error occured while Creating the CSR", err)
kubeconfig, err := findKubeConfig()
check("The following error occured while getting the Kube Config file", err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment