keel-hq / keel

Kubernetes Operator to automate Helm, DaemonSet, StatefulSet & Deployment updates
https://keel.sh
Mozilla Public License 2.0
2.46k stars 282 forks source link

Slack approvals through message buttons #141

Closed victorandree closed 6 years ago

victorandree commented 6 years ago

It would be neat if you could just press a button in Slack to vote for approvals. I figure this should be possible using interactive message buttons. The example on that page is quite neat:

I guess the main hurdle to achieving this is actually to support Slack apps rather than (legacy) custom integrations/bot users?

rusenask commented 6 years ago

Hi, that would indeed be neat. When I started working on approvals I imagined that we will have buttons. The problem with buttons is that those interactive messages are only supported for SaaS products, they want public endpoints where they can send webhooks (apps that use slack RTM API cannot receive those button responses).

So, unless they made it possible for standalone apps to use these buttons, there is no straightforward way to implement this.

victorandree commented 6 years ago

I understand. For those willing to achieve this, I imagine the current solution would be to build our own integration using keel webhooks instead? Would it be possible to have the built-in bot optionally use the Slack web API instead?

rusenask commented 6 years ago

It would be possible. I would have to refresh my memory but I think it's just about:

  1. formatting messages in a different format
  2. having additional endpoint that expects Slack webhooks. One of the downsides would be exposing Keel to the world but https://webhookrelay.com could help out :)
victorandree commented 6 years ago

Started to have a look at rolling something of our own here (using our own bot), but doesn't seem like we can do approvals over the HTTP API? https://github.com/keel-hq/keel/blob/7d7580db0eefa6237bb63d53518831aea4de3515/trigger/http/http.go#L87

That would be quite useful, I think. How about POST /v1/approvals with body as below (or should it be another native webhook even?):

{
  "identifier": "default/wd:0.0.15",
  "voter": "victorandree"
}

which more or less simply is this:

func (s *TriggerServer) approvalApproveHandler(resp http.ResponseWriter, req *http.Request) {
    // parsen json ApprovalRequest

    err := s.approvalsManager.Approve(approval.Identifier, approval.Voter)
    if err != nil {
        fmt.Fprintf(resp, "%s", err)
        resp.WriteHeader(http.StatusInternalServerError)
        return
    }

    // Maybe something useful like returning the updated Approval
    resp.WriteHeader(http.StatusOK)
    fmt.Fprintf(resp, identifier)
}
rusenask commented 6 years ago

Yes, definitely something that has to be added to the HTTP endpoints. Are you still going to use Keel internally (not exposed to the internet) or we should have some basic auth on at least approval handlers?

victorandree commented 6 years ago

I think we won't expose it, but keep it internal. It could make sense to be able to configure a list of authorized voters, however?

rusenask commented 6 years ago

Without authentication anyone could post a payload with any voter name. Voter names were added to remove duplicates from slack messages, so the same user couldn't vote 2 or more times. I guess with HTTP endpoint this responsibility would have to fall on the system that's using it.

It could get a list of approvals with existing voters to check for duplicates though.

rusenask commented 6 years ago

Hi, I think I got right now (initially though about using identifiers in the URL but it's better not to). The API now is:

Method: POST Endpoint: /v1/approvals

{
  "identifier": "default/myimage:1.5.5", // identifier for the approval request
  "action": "approve", // approve/reject/delete, defaults to "approve"
  "voter": "john",  
}