Skip to content

Commit

Permalink
added support for insecure-skip-tls-verify (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebastiani authored Dec 4, 2023
1 parent 7a326cc commit dc1d448
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
15 changes: 15 additions & 0 deletions model_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ConnectionParameters struct {

BearerToken string `json:"bearerToken"`
BearerTokenFile string `json:"bearerTokenFile"`
Insecure bool `json:"insecure"`
}

// UnmarshalJSON uses the Arcaflow schema system to unmarshal JSON data when called via json.Unmarshal on the
Expand Down Expand Up @@ -268,6 +269,20 @@ var connectionParametersSchema = schema.NewTypedObject[ConnectionParameters](
schema.PointerTo(util.JSONEncode("/var/run/secrets/kubernetes.io/serviceaccount")),
nil,
),
"insecure": schema.NewPropertySchema(
schema.NewBoolSchema(),
schema.NewDisplayValue(
schema.PointerTo("Insecure connection"),
schema.PointerTo("Skip TLS verification"),
nil,
),
false,
nil,
nil,
nil,
nil,
nil,
),
},
)

Expand Down
2 changes: 1 addition & 1 deletion model_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ var clusterParamsSchema = schema.NewTypedObject[KubeConfigClusterParams](
nil,
).TreatEmptyAsDefaultValue(),
"insecure-skip-tls-verify": schema.NewPropertySchema(
schema.NewStringSchema(schema.IntPointer(1), nil, nil),
schema.NewBoolSchema(),
schema.NewDisplayValue(
schema.PointerTo("InsecureSkipTLSVerify"),
schema.PointerTo("toggles TLS verification"),
Expand Down
10 changes: 4 additions & 6 deletions parse_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ func KubeConfigToConnection(kubeconfig KubeConfig, inlineFiles bool) (Connection
return ConnectionParameters{}, fmt.Errorf("current user %s not found in kubeconfig file", currentUser)
}

if cluster.Cluster.InsecureSkipTLSVerify {
return ConnectionParameters{}, errors.New("the Kubeconfig is set to skip TLS verification" +
"this is not supported by arcaflow and there is no reason to use this option" +
"please set up your kubernetes TLS authentication with CA certificates.")
}

if len(cluster.Cluster.Server) == 0 {
return ConnectionParameters{}, errors.New("no cluster host found in connection")
}
Expand All @@ -87,6 +81,8 @@ func KubeConfigToConnection(kubeconfig KubeConfig, inlineFiles bool) (Connection
}
}

connectionParams.Insecure = cluster.Cluster.InsecureSkipTLSVerify

if cluster.Cluster.CertificateAuthorityData != nil {
connectionParams.CAData = util.Base64Decode(*cluster.Cluster.CertificateAuthorityData)
}
Expand Down Expand Up @@ -152,6 +148,7 @@ func ConnectionToKubeConfig(connection ConnectionParameters) (KubeConfig, error)
if len(connection.CAFile) > 0 {
clusterParams.CertificateAuthority = &connection.CAFile
}
clusterParams.InsecureSkipTLSVerify = connection.Insecure
cluster := KubeConfigCluster{
Cluster: clusterParams,
Name: defaultStr,
Expand Down Expand Up @@ -243,6 +240,7 @@ func ConnectionToRestConfig(connection ConnectionParameters) (*restclient.Config
KeyFile: connection.KeyFile,
CAData: []byte(connection.CAData),
CAFile: connection.CAFile,
Insecure: connection.Insecure,
},
UserAgent: "Arcaflow",
QPS: restclient.DefaultQPS,
Expand Down
7 changes: 5 additions & 2 deletions parse_kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func TestKubeConfigToConnection(t *testing.T) {
assert.Equal(t, connection.KeyData, fixtures.clientKey)
assert.Equal(t, connection.CAData, fixtures.caCert)
assert.Equal(t, connection.CertData, fixtures.clientCrt)
// test that by default insecure-skip-tls-verify is false
assert.False(t, connection.Insecure)

//test without inlining
kubeconf, err = ParseKubeConfig(fixtures.kubeconfigNoData)
Expand All @@ -105,10 +107,11 @@ func TestKubeConfigToConnection(t *testing.T) {
assert.NotNil(t, err)
err = nil

//test failure on insecure-skip-tls-verify: true
//test success on insecure-skip-tls-verify: true
kubeconf, err = ParseKubeConfig(fixtures.kubeconfigSkipTls)
connection, err = KubeConfigToConnection(kubeconf, true)
assert.NotNil(t, err)
assert.True(t, connection.Insecure)
assert.Nil(t, err)
}

func TestConnectionToKubeConfig(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions testdata/kubeconfig-tlsskip.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM5ekNDQWQrZ0F3SUJBZ0lVV01PTVBNMVUrRi9uNXN6TSthYzlMcGZISHB3d0RRWUpLb1pJaHZjTkFRRUwKQlFBd0hqRWNNQm9HQTFVRUF3d1RhM1ZpZFc1MGRTNXNiMk5oYkdSdmJXRnBiakFlRncweU1URXlNRFl4T0RBdwpNRFJhRncwek1URXlNRFF4T0RBd01EUmFNQjR4SERBYUJnTlZCQU1NRTJ0MVluVnVkSFV1Ykc5allXeGtiMjFoCmFXNHdnZ0VpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDNExhcG00SDB0T1NuYTNXVisKdzI4a0tOWWRwaHhYOUtvNjUwVGlOK2c5ZFNQU3VZK0V6T1JVOWVONlgyWUZkMEJmVFNodno4Y25rclAvNysxegpETEoxQ3MwRi9haEV3ZDQxQXN5UGFjbnRiVE80dGRLWm9POUdyODR3YVdBN1hSZmtEc2ZxRGN1YW5UTmVmT1hpCkdGbmdDVzU5Q285M056alB1eEFrakJxdVF6eE5GQkgwRlJPbXJtVFJ4cnVLZXo0aFFuUW1OWEFUNnp0M21udzMKWUtWTzU4b2xlcUxUcjVHNlRtVFQyYTZpVGdtdWY2N0cvaVZlalJGbkw3YkNHWmgzSjlCSTNMcVpqRzE4dWxvbgpaVDdQcGQrQTlnaTJOTm9UZlI2TVB5SndxU1BCL0xZQU5ZNGRoZDVJYlVydDZzbmViTlRZSHV2T0tZTDdNTWRMCmVMSzFBZ01CQUFHakxUQXJNQWtHQTFVZEV3UUNNQUF3SGdZRFZSMFJCQmN3RllJVGEzVmlkVzUwZFM1c2IyTmgKYkdSdmJXRnBiakFOQmdrcWhraUc5dzBCQVFzRkFBT0NBUUVBQTVqUHVpZVlnMExySE1PSkxYY0N4d3EvVzBDNApZeFpncVd3VHF5VHNCZjVKdDlhYTk0SkZTc2dHQWdzUTN3NnA2SlBtL0MyR05MY3U4ZWxjV0E4UXViQWxueXRRCnF1cEh5WnYrZ08wMG83TXdrejZrTUxqQVZ0QllkRzJnZ21FRjViTEk5czBKSEhjUGpHUkl1VHV0Z0tHV1dPWHgKSEg4T0RzaG9wZHRXMktrR2c2aThKaEpYaWVIbzkzTHptM00xRUNGcXAvMEdtNkN1RFphVVA2SGpJMWRrYllLdgpsSHNVZ1U1SmZjSWhNYmJLdUllTzRkc1YvT3FHcm9iNW5vcmRjaExBQmRDTnc1cmU5T1NXZGZ1VVhSK0ViZVhrCjVFM0tFYzA1RGNjcGV2a1NTdlJ4SVQrQzNMOTltWGcxL3B5NEw3VUhvNFFLTXlqWXJXTWlLRlVKV1E9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
server: https://127.0.0.1:6443
insecure-skip-tls-verify: true
certificate-authority: testdata/ca.crt
name: default
contexts:
- context:
Expand All @@ -16,8 +17,9 @@ preferences: {}
users:
- name: testuser
user:
client-certificate: testdata/client.crt
client-key: testdata/client.key
client-key-data: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2QUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktZd2dnU2lBZ0VBQW9JQkFRQzRMYXBtNEgwdE9TbmEKM1dWK3cyOGtLTllkcGh4WDlLbzY1MFRpTitnOWRTUFN1WStFek9SVTllTjZYMllGZDBCZlRTaHZ6OGNua3JQLwo3KzF6RExKMUNzMEYvYWhFd2Q0MUFzeVBhY250YlRPNHRkS1pvTzlHcjg0d2FXQTdYUmZrRHNmcURjdWFuVE5lCmZPWGlHRm5nQ1c1OUNvOTNOempQdXhBa2pCcXVRenhORkJIMEZST21ybVRSeHJ1S2V6NGhRblFtTlhBVDZ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LdUllTzRkc1YvT3FHcm9iNW5vcmRjaExBQmRDTnc1cmU5T1NXZGZ1VVhSK0ViZVhrCjVFM0tFYzA1RGNjcGV2a1NTdlJ4SVQrQzNMOTltWGcxL3B5NEw3VUhvNFFLTXlqWXJXTWlLRlVKV1E9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
username: testuser
password: testpassword
token: sha256~fFyEqjf1xxFMO0tbEyGRvWeNOd7QByuEgS4hyEq_A9o
token: sha256~fFyEqjf1xxFMO0tbEyGRvWeNOd7QByuEgS4hyEq_A9o

0 comments on commit dc1d448

Please sign in to comment.