> For the complete documentation index, see [llms.txt](https://docs.keeper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/heroku.md).

# Heroku

![](/files/Z3wUXqtFx15nVC4Zwil2)

## 機能 <a href="#features" id="features"></a>

* シークレット認証情報をKeeperボルトに安全に保存し、Herokuで公開せずに利用
* KeeperボルトからHerokuアプリへファイルをコピー
* Herokuから他の[シークレットマネージャーSDK](/keeperpam/jp/secrets-manager/developer-sdk-library.md)機能 (レコード作成やTOTPコードなど) を利用

{% hint style="info" %}
Keeperシークレットマネージャーの機能一覧については、[概要](/keeperpam/jp/secrets-manager/overview.md)をご参照ください。
{% endhint %}

## 概要 <a href="#about" id="about"></a>

Herokuには、アプリケーションの設定変数を保存する機能があります。ただし、値は閲覧可能な形式で保存されます。Keeperシークレットマネージャーを使用すると、機密シークレットをゼロ知識環境のKeeperボルトに保存できます。

Herokuでは、以下のKeeperシークレットマネージャーSDKを使用できます。

* [Python](/keeperpam/jp/secrets-manager/developer-sdk-library/python-sdk.md)
* [GoLang](/keeperpam/jp/secrets-manager/developer-sdk-library/golang-sdk.md)
* [Java](/keeperpam/jp/secrets-manager/developer-sdk-library/java-sdk.md)
* [Javascript](/keeperpam/jp/secrets-manager/developer-sdk-library/javascript-sdk.md)

以下の例では、KeeperシークレットマネージャーとHerokuの連携でできることを確認できます。

## 例 - Python SDKを使用したSlack通知 <a href="#example-slack-notification-using-python-sdk" id="example-slack-notification-using-python-sdk"></a>

この例では、KeeperシークレットマネージャーSDKでWebhookトークンを取得し、HerokuウェブアプリケーションからSlackチャネルにメッセージを送信します。

### Slackの設定 <a href="#slack-setup" id="slack-setup"></a>

最初の手順は、SlackインスタンスからWebhookトークンを取得することです。SlackのWebサイトにログインし、[Your Apps](https://api.slack.com/apps)に移動します。

![](/files/ivoiBcEm8xt8ITNFoFMA)

**\[Create New App]** ボタンをクリックし、ダイアログで **\[From scratch]** を選択して新しいアプリを作成します。**App Name**を入力し、アプリを開発するワークスペースを選択します。

次に、Incoming Webhooksボタンをクリックします。

![](/files/oFK6b9LEyQGbYYrd8yF7)

Incoming Webhooksをオンにします。**Webhook URLs for Your Workspace**セクションが表示されたら、**\[Add New Webhook to Workspace]** ボタンをクリックします。

![](/files/6cfDnxFoCsV9RAHez8DR)

ワークスペース内のチャネルを選択します。

![](/files/ngFCM3HIuyAk2o4gSafn)

Incoming Webhooksページの下部に**Webhook URL**が表示されます。この例では、URLを**Copy**してKeeperボルトのレコードに保存します。

![](/files/iYiPxYqZG6jlMIHkFdgs)

### Keeperボルトの設定 <a href="#keeper-vault-setup" id="keeper-vault-setup"></a>

Keeperボルトで、共有フォルダ内にSlack**Webhook URL**を保存するログインレコードを作成します。共有フォルダはアプリケーションに追加できます。詳細は[クイックスタートガイド](/keeperpam/jp/secrets-manager/quick-start-guide.md)をご参照ください。

**Webhook URL**をログインレコードの\*\*\[Website Address]**フィールドにコピーして保存します。保存後、レコードの情報アイコン**<img src="/files/zg1SzZc5yhM7h9FSgfG8" alt="" data-size="line">**をクリックして**レコードUID**を確認します。レコードUIDのURLをクリップボードにコピーすると、実際の**レコードUID\*\*を含められます。必要なのはURL内のUID部分のみです。

### Heroku <a href="#heroku-1" id="heroku-1"></a>

この例では、[Herokuアカウント](https://signup.heroku.com/dc)とPython 3が必要です。次に、[手順](https://devcenter.heroku.com/articles/getting-started-with-python#set-up)に従ってHeroku CLIをインストールします。

Heroku CLIをインストールしたら、アプリケーションを作成できます。

```bash
$ heroku create
Creating app... done, ⬢ random-name-30564
https://random-name-30564.herokuapp.com/ | https://git.heroku.com/random-name-30564.git
```

{% hint style="info" %}
生成されるアプリケーション名は、この例とは異なります。
{% endhint %}

空のGitリポジトリが作成されます。リポジトリをクローンできます (空である旨の警告が表示されます)。その後、リポジトリディレクトリに移動します。

```bash
$ git clone https://git.heroku.com/random-name-30564.git
Cloning into 'random-name-30564'...
warning: You appear to have cloned an empty repository.

$ cd random-name-30564
```

リポジトリをクローンしたら、設定変数を設定できます。設定が必要な変数は2つです。1つ目は**RECORD\_UID**で、Webhook URLを含むレコードのUIDです。2つ目は**KSM\_CONFIG**で、Base64エンコードされたシークレットマネージャー構成を含みます。

{% hint style="info" %}
Base64構成の作成方法については、[構成ドキュメント](/keeperpam/jp/secrets-manager/about/secrets-manager-configuration.md#using-a-cli-tool)をご参照ください。
{% endhint %}

```bash
$ heroku config:set RECORD_UID=XXXXXX
Setting RECORD_UID and restarting ⬢ random-name-30564... done, v11
RECORD_UID: XXXXXX

$ heroku config:set KSM_CONFIG=ewogI ..... Igp9
Setting KSM_CONFIG and restarting ⬢ random-name-30564... done, v11
KSM_CONFIG: ewogI ..... Igp9
```

設定変数の準備ができたら、アプリケーションを追加します。最初の手順は、Python 3アプリケーションの要件を定義することです。**requirements.txt**には、ウェブサイト用の**Flask**、Slack通信用の**slack\_sdk**、シークレットマネージャー通信用の**keeper-secrets-manager-core**が含まれます。

```bash
$ cat << EOF > requirements.txt
Flask
slack_sdk
keeper-secrets-manager-core
EOF
```

任意のエディタで、以下の内容を**app.py**に保存します。

```python
import os
from flask import Flask, request
from slack_sdk.webhook import WebhookClient
from keeper_secrets_manager_core import SecretsManager

app = Flask(__name__)
secret_manager = SecretsManager()
record_id = os.environ.get("RECORD_UID")
webhook = WebhookClient(secret_manager.get_notation("{}/field/url".format(record_id)))


@app.route('/')
def hello():

    message = request.args.get("message")
    if message is not None and message != "":
        response = webhook.send(text=message)

    html = """
<html>
    <head><title>Send a Slack Message</title></head>
    <body>
        <form method="GET">
            Message:
            <input type="text" name="message" />
            <input type="submit" />
        </form>
    </body>
</html>
    """

    return html


if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

```

フォーム入力ボックスと送信ボタンを表示するシンプルなFlaskウェブアプリケーションです。入力したテキストはSlackチャネルに送信されます。

最後に、ProcfileでHerokuにアプリケーションの起動方法を指定します。

```bash
$ cat << EOF > Procfile
web: python app.py
EOF
```

アプリケーションを実行する準備ができました。Gitリポジトリにファイルを追加し、mainブランチをプッシュすると、ビルドと起動が行われます。

```bash
$ git add requirements.txt app.py Procfile
$ git commit -m "Initial Commit"
[main 0f31f23] Initial Commit
 3 file changed, 0 insertion(+), 0 deletion(-)
...

$ git push origin main
...
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/python
remote: -----> Python app detected
remote: -----> No Python version was specified. Using the same version as the last build: python-3.9.9
remote:        To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> No change in requirements detected, installing from cache
remote: -----> Using cached install of python-3.9.9
remote: -----> Installing pip 21.3.1, setuptools 57.5.0 and wheel 0.37.0
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 62.4M
remote: -----> Launching...
remote:        Released v13
remote:        https://random-name-30564.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/random-name-30564.git
   89b16a2..fda1835  main -> main
```

URL (`https://random-name-30564.herokuapp.com/`) にアクセスするか、以下のコマンドでウェブサイトを開けます。

```
$ heroku open
```

シンプルなウェブサイトが表示されます。メッセージを入力してSubmitをクリックします。

![](/files/9bJaPoaYqj0DYsm42Jzl)

作成したWebhookのチャネルにメッセージが表示されます。

![](/files/ktHIdIrJC25Lfr5kPifM)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/secrets-manager/integrations/heroku.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
