templates

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSSHTemplateData = map[string]string{

	"config.tpl": `Host *
{{- if or .User.GOOS "none" | eq "windows" }}
{{- if .User.StepBasePath }}
	Include "{{ .User.StepBasePath | replace "\\" "/" | trimPrefix "C:" }}/ssh/includes"
{{- else }}
	Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/includes"
{{- end }}
{{- else }}
{{- if .User.StepBasePath }}
	Include "{{.User.StepBasePath}}/ssh/includes"
{{- else }}
	Include "{{.User.StepPath}}/ssh/includes"
{{- end }}
{{- end }}`,

	"step_includes.tpl": `{{- if or .User.GOOS "none" | eq "windows" }}Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"{{- else }}Include "{{.User.StepPath}}/ssh/config"{{- end }}`,

	"step_config.tpl": `Match exec "step ssh check-host{{- if .User.Context }} --context {{ .User.Context }}{{- end }} %h"
{{- if .User.User }}
	User {{.User.User}}
{{- end }}
{{- if or .User.GOOS "none" | eq "windows" }}
	UserKnownHostsFile "{{.User.StepPath}}\ssh\known_hosts"
	ProxyCommand C:\Windows\System32\cmd.exe /c step ssh proxycommand{{- if .User.Context }} --context {{ .User.Context }}{{- end }} %r %h %p
{{- else }}
	UserKnownHostsFile "{{.User.StepPath}}/ssh/known_hosts"
	ProxyCommand step ssh proxycommand{{- if .User.Context }} --context {{ .User.Context }}{{- end }} %r %h %p
{{- end }}
`,

	"known_hosts.tpl": `@cert-authority * {{.Step.SSH.HostKey.Type}} {{.Step.SSH.HostKey.Marshal | toString | b64enc}}
{{- range .Step.SSH.HostFederatedKeys}}
@cert-authority * {{.Type}} {{.Marshal | toString | b64enc}}
{{- end }}
`,

	"sshd_config.tpl": `Match all
	TrustedUserCAKeys /etc/ssh/ca.pub
	HostCertificate /etc/ssh/{{.User.Certificate}}
	HostKey /etc/ssh/{{.User.Key}}`,

	"ca.tpl": `{{.Step.SSH.UserKey.Type}} {{.Step.SSH.UserKey.Marshal | toString | b64enc}}
{{- range .Step.SSH.UserFederatedKeys}}
{{.Type}} {{.Marshal | toString | b64enc}}
{{- end }}
`,
}

DefaultSSHTemplateData contains the data of the default templates used on ssh.

View Source
var DefaultSSHTemplates = SSHTemplates{
	User: []Template{
		{
			Name:         "config.tpl",
			Type:         Snippet,
			TemplatePath: "templates/ssh/config.tpl",
			Path:         "~/.ssh/config",
			Comment:      "#",
		},
		{
			Name:         "step_includes.tpl",
			Type:         PrependLine,
			TemplatePath: "templates/ssh/step_includes.tpl",
			Path:         "${STEPPATH}/ssh/includes",
			Comment:      "#",
		},
		{
			Name:         "step_config.tpl",
			Type:         File,
			TemplatePath: "templates/ssh/step_config.tpl",
			Path:         "ssh/config",
			Comment:      "#",
		},
		{
			Name:         "known_hosts.tpl",
			Type:         File,
			TemplatePath: "templates/ssh/known_hosts.tpl",
			Path:         "ssh/known_hosts",
			Comment:      "#",
		},
	},
	Host: []Template{
		{
			Name:         "sshd_config.tpl",
			Type:         Snippet,
			TemplatePath: "templates/ssh/sshd_config.tpl",
			Path:         "/etc/ssh/sshd_config",
			Comment:      "#",
			RequiredData: []string{"Certificate", "Key"},
		},
		{
			Name:         "ca.tpl",
			Type:         Snippet,
			TemplatePath: "templates/ssh/ca.tpl",
			Path:         "/etc/ssh/ca.pub",
			Comment:      "#",
		},
	},
}

DefaultSSHTemplates contains the configuration of default templates used on ssh. Relative paths are relative to the StepPath.

View Source
var SSHTemplateVersionKey = "StepSSHTemplateVersion"

SSHTemplateVersionKey is a key that can be submitted by a client to select the template version that will be returned by the server.

Functions

func LoadAll

func LoadAll(t *Templates) (err error)

LoadAll preloads all templates in memory. It returns an error if an error is found parsing at least one template.

func StepFuncMap added in v0.18.0

func StepFuncMap() template.FuncMap

StepFuncMap returns sprig.TxtFuncMap but removing the "env" and "expandenv" functions to avoid any leak of information.

Types

type Output

type Output struct {
	Name    string       `json:"name"`
	Type    TemplateType `json:"type"`
	Path    string       `json:"path"`
	Comment string       `json:"comment"`
	Content []byte       `json:"content"`
}

Output represents the text representation of a rendered template.

func (*Output) Write

func (o *Output) Write() error

Write writes the Output to the filesystem as a directory, file or snippet.

type SSHTemplates

type SSHTemplates struct {
	User []Template `json:"user"`
	Host []Template `json:"host"`
}

SSHTemplates contains the templates defining ssh configuration files.

func (*SSHTemplates) Validate

func (t *SSHTemplates) Validate() (err error)

Validate returns an error if a template is not valid.

type Step

type Step struct {
	SSH StepSSH
}

Step represents the default variables available in the CA.

type StepSSH

type StepSSH struct {
	HostKey           ssh.PublicKey
	UserKey           ssh.PublicKey
	HostFederatedKeys []ssh.PublicKey
	UserFederatedKeys []ssh.PublicKey
}

StepSSH holds SSH-related values for the CA.

type Template

type Template struct {
	*template.Template
	Name         string       `json:"name"`
	Type         TemplateType `json:"type"`
	TemplatePath string       `json:"template"`
	Path         string       `json:"path"`
	Comment      string       `json:"comment"`
	RequiredData []string     `json:"requires,omitempty"`
	Content      []byte       `json:"-"`
}

Template represents a template file.

func (*Template) Load

func (t *Template) Load() error

Load loads the template in memory, returns an error if the parsing of the template fails.

func (*Template) LoadBytes

func (t *Template) LoadBytes(b []byte) error

LoadBytes loads the template in memory, returns an error if the parsing of the template fails.

func (*Template) Output

func (t *Template) Output(data interface{}) (Output, error)

Output renders the template and returns a template.Output struct or an error.

func (*Template) Render

func (t *Template) Render(data interface{}) ([]byte, error)

Render executes the template with the given data and returns the rendered version.

func (*Template) Validate

func (t *Template) Validate() error

Validate returns an error if the template is not valid.

func (*Template) ValidateRequiredData added in v0.14.5

func (t *Template) ValidateRequiredData(data map[string]string) error

ValidateRequiredData checks that the given data contains all the keys required.

type TemplateType

type TemplateType string

TemplateType defines how a template will be written in disk.

const (
	// Snippet will mark a template as a part of a file.
	Snippet TemplateType = "snippet"
	// PrependLine is a template for prepending a single line to a file. If the
	// line already exists in the file it will be removed first.
	PrependLine TemplateType = "prepend-line"
	// File will mark a templates as a full file.
	File TemplateType = "file"
	// Directory will mark a template as a directory.
	Directory TemplateType = "directory"
)

type Templates

type Templates struct {
	SSH  *SSHTemplates          `json:"ssh,omitempty"`
	Data map[string]interface{} `json:"data,omitempty"`
}

Templates is a collection of templates and variables.

func DefaultTemplates added in v0.14.5

func DefaultTemplates() *Templates

DefaultTemplates returns the default templates.

func (*Templates) Validate

func (t *Templates) Validate() (err error)

Validate returns an error if a template is not valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL