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

export configuration as plain text with secrets? #2004

Closed
zetaab opened this issue Aug 20, 2019 · 4 comments
Closed

export configuration as plain text with secrets? #2004

zetaab opened this issue Aug 20, 2019 · 4 comments

Comments

@zetaab
Copy link

zetaab commented Aug 20, 2019

I am trying to export alertmanager configuration as plain text, because I am inserting it to kubernetes configmap. The problem is that when I marshal/unmarshal things the secrets are replaced with <secret>. Is there any way to avoid removing secrets from the configuration.

Example

	alertmanager := &config.Config{
		Receivers: []*config.Receiver{
			{
				Name: "kapi",
				WebhookConfigs: []*config.WebhookConfig{
					{
						NotifierConfig: config.NotifierConfig{
							VSendResolved: true,
						},
						HTTPConfig: &commoncfg.HTTPClientConfig{
							BearerToken: commoncfg.Secret("placeholder"),
						},
						URL: &config.URL{URL: "https://google.fi"},
					},
				},
			},
		},
		Route: &config.Route{
			Receiver:       "kapi",
			RepeatInterval: &dur,
		},
	}

alertmanager.String() will produce:

        route:
          receiver: kapi
          repeat_interval: 1d
        receivers:
        - name: kapi
          webhook_configs:
          - send_resolved: true
            http_config:
              bearer_token: <secret>
            url: https://google.fi
        templates: []

instead I would like to have

        route:
          receiver: kapi
          repeat_interval: 1d
        receivers:
        - name: kapi
          webhook_configs:
          - send_resolved: true
            http_config:
              bearer_token: placeholder
            url: https://google.fi
        templates: []

Of course I can run strings.Replace(alertmanager.String(), "<secret>", "placeholder", -1). However, the problem starts when there are multiple secrets in configuration.

@zetaab zetaab changed the title export configuration as plain text? export configuration as plain text with secrets? Aug 20, 2019
@mxinden
Copy link
Member

mxinden commented Aug 20, 2019

Hi @zetaab,

You might find some answers in #1985 and #1985.

@brian-brazil
Copy link
Contributor

You could work from the file on disk.

@simonpasquier
Copy link
Member

Closing as a duplicate of #1985.

@zetaab
Copy link
Author

zetaab commented Sep 3, 2019

@brian-brazil do you have tip for that? I tried following

	alertmanager := &config.Config{
		Receivers: []*config.Receiver{
			{
				Name:           "kapi",
				WebhookConfigs: webconfigs,
				SlackConfigs:   slackconfigs,
			},
		},
		Route: &config.Route{
			Receiver:       "kapi",
			RepeatInterval: &dur,
		},
	}

	// write to disk
	dir, err := ioutil.TempDir("", "alertmanager")
	if err != nil {
		return "", err
	}
	defer os.RemoveAll(dir)

	newpath := filepath.Join(dir, "alertmanager.cfg")
	err = os.MkdirAll(filepath.Dir(newpath), os.ModePerm)
	if err != nil {
		glog.Errorf("error creating directory to %v", err)
		return "", err
	}

	jsonValue, err := json.Marshal(alertmanager)
	if err != nil {
		glog.Errorf("Marshal error %v", err)
		return "", err
	}

	err = ioutil.WriteFile(newpath, []byte(jsonValue), 0644)
	if err != nil {
		glog.Errorf("error writing to %s %v", newpath, err)
		return "", err
	}

but the problem is that in file its still <secret>

So I am trying to make new alertmanager configuration using alertmanager libs and then output that as string or similar. However, for me this looks like really difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants