# カスタムタスクでネットワークアクセスを有効にする

> カスタムタスクでネットワークアクセスを有効にする - カスタムタスクからパブリックネットワークへアクセスできるように設定します。

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-07-15T05:55:44.964495+00:00` (UTC).

## Primary page

- [カスタムタスクでネットワークアクセスを有効にする](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/cml/custom-task-network-access.html.md): Full documentation for this topic (Markdown sidecar).

## Sections on this page

- [資格情報IDの取得](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/cml/custom-task-network-access.html.md#id): In-page section heading.
- [資格情報の設定](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/cml/custom-task-network-access.html.md#_1): In-page section heading.
- [パブリックIPアドレスへのアクセスを有効にする](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/cml/custom-task-network-access.html.md#ip): In-page section heading.
- [DRUMでローカルにテストする](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/cml/custom-task-network-access.html.md#drum): In-page section heading.
- [コマンド例](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/cml/custom-task-network-access.html.md#_2): In-page section heading.
- [シークレットの詳細](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/cml/custom-task-network-access.html.md#_3): In-page section heading.

## Documentation content

カスタムタスクからパブリックネットワークへのアクセスを設定できるようになりました。 このページのコード例では、資格情報を持つAPIエンドポイントを使用してネットワークアクセスを確保する二値推定タスクを紹介しています。

## 資格情報IDの取得

ネットワークアクセスを設定する前に、資格情報IDを指定する必要があります。 独自の [資格情報](https://docs.datarobot.com/ja/docs/platform/acct-settings/stored-creds.html.md#credentials-management) を設定した後、DataRobotのユーザープロフィールを開き、 資格情報管理 を選択します。

資格情報を選択します。 選択すると、資格情報IDをコピーできます。 IDはURLの `/credentials-management/` に続く文字列です。

## 資格情報の設定

`model-metadata.yaml` に資格情報を追加する方法については、以下の例を参照してください。 [DRUMリポジトリ](https://github.com/datarobot/datarobot-user-models/tree/master/task_templates/2_estimators/13_python_credentials_and_internet_access/model-metadata.yaml) にあるサンプルファイルにアクセスできます。 `typeSchema` はDRUMリポジトリの [別の例](https://github.com/datarobot/datarobot-user-models/tree/master/task_templates/2_estimators/4_python_binary_classification) からコピーしたものです。

```
# Example: model-metadata.yaml
name: 13_python_credentials_and_internet_access
type: training
environmentID: 5e8c889607389fe0f466c72d
targetType: binary

# These must be actual DataRobot credentials that the author owns
userCredentialSpecifications:
  - key: MY_CREDENTIAL  # A legal POSIX env var key
    valueFrom: 655270e368a555f026e2512d  # A credential ID from DataRobot for which you are the owner
    reminder: my super-cool.com/api api-token  # Optional: any string value that you for a reminder

typeSchema:
  input_requirements:
    - field: data_types
      condition: IN
      value:
        - NUM
    - field: number_of_columns
      condition: NOT_LESS_THAN
      value: 2
    - field: sparse
      condition: EQUALS
      value: SUPPORTED
# This requirement is only ignored because this is an example using test data 
```

## パブリックIPアドレスへのアクセスを有効にする

カスタムタスク内からネットワークにアクセスするには、カスタムタスクバージョンで `outgoingNetworkPolicy` フィールドを使用して明示的に有効にする必要があります。 新しいバージョンは、別のものを指定しない限り、前のバージョンの `outgoingNetworkPolicy` を継承します。 これを行うには、REST APIを使用する必要があります。

> [!NOTE] 本機能の提供について
> カスタムタスクのネットワークアクセスには、DataRobotの早期アクセスPythonクライアントを使用する必要があります。 早期アクセスクライアントは、 `pip install datarobot_early_access` を使ってインストールできます。

```
from datarobot.enums import CustomTaskOutgoingNetworkPolicy

task_version = dr.CustomTaskVersion.create_clean(
    custom_task_id=custom_task_id,
    base_environment_id=execution_environment.id,
    folder_path=custom_task_folder,
    outgoing_network_policy=CustomTaskOutgoingNetworkPolicy.PUBLIC,
) 
```

詳細については、 [Pythonクライアントのドキュメント](https://datarobot-public-api-client.readthedocs-hosted.com/en/early-access/reference/modeling/spec/custom_task.html#create-custom-task-version) を参照してください。

## DRUMでローカルにテストする

DRUMで資格情報を使ってテストしたい場合は、シークレット用のディレクトリを作成し、そこにすべてのシークレットを置くことで、偽のデータを作成できます。 DRUMリポジトリで [この例](https://github.com/datarobot/datarobot-user-models/tree/master/task_templates/2_estimators/13_python_credentials_and_internet_access/secrets) を参照できます。

### コマンド例

```
drum fit -cd task_templates/2_estimators/13_python_credentials_and_internet_access/ \
--input tests/testdata/10k_diabetes.csv --target-type binary --target readmitted \
--user-secrets-mount-path task_templates/2_estimators/13_python_credentials_and_internet_access/ \
--verbose --logging-level info --show-stacktrace 
```

### シークレットの詳細

各シークレットファイルには、同名の対応する資格情報が必要です。 シークレットファイルの内容は、いずれかのシークレットオブジェクトにキャストできるJSON文字列である必要があります。 すべてのシークレットオブジェクトが `custom_model_runner/datarobot_drum/custom_task_interfaces/user_secrets.py` にあります。 シークレットの回答には `credential_type` が含まれている必要があります。これは、 `datarobot_drum.custom_task_interfaces.user_secrets.SecretType` の別名です。ただし、値はすべて英小文字である必要があります（ `SecretType.SNOWFLAKE_KEY_PAIR_USER_ACCOUNT` は `{"credential_type": "snowflake_key_pair_user_account"}` に対応します）。

例：

```
@dataclass(frozen=True)
class SnowflakeKeyPairUserAccountSecret(AbstractSecret):
    username: Optional[str]
    private_key_str: Optional[str]
    passphrase: Optional[str] = None
    config_id: Optional[str] = None 
```

次のようになります。

```
{
  "credential_type": "snowflake_key_pair_user_account",
  "username": "bob@bob.com",
  "private_key_str": "shhhhhhhh"
} 
```
