@azbake/ingredient-storage

中文文档
0.6.0发布于 2026/08/19MITTypeScriptCommonJS近 30 天下载 4294

Ingredient for deploying a storage account

原始使用文档
文档目录11 节
  1. Changelogs
  2. Overview
  3. Usage
  4. Recipe
  5. Anonymous public blob access
  6. Public network access (Pass-1 stub — tag only)
  7. Uploading Files to Blob Storage
  8. Utilities
  9. storage class
  10. Function Details
  11. Lifecycle Management Policies

Changelogs

Overview

The Storage ingredient is a plugin for Bake. When included in a recipe this will create a standard storage account. Whether services blob, file, disk, queue, or table storage are mounted on this resource is not defined in the template, only the logical construct is created.

Usage

This typically would be included as a dependent resource in a recipe. It is possible to setup a stand alone instance, but would not be a typical inclusion. Metrics and diagnostic logs are recorded to Storage Analytics is enabled by default.

Recipe

name: My package
shortName: mypkg
version: 0.0.1
ingredients:
  - "@azbake/ingredient-storage@~0"
parallelRegions: false
resourceGroup: true
variables:
  #"true" or "false" strings.  Defaults to "true" if unspecified.
  blobDiagnosticHourlyMetricsEnabled: "true"
  #Number of days to retain hourly metrics
  blobDiagnosticHourlyMetricsRetentionDays: 12
  #"true" or "false" strings.  Defaults to "true" if unspecified.
  blobDiagnosticMinuteMetricsEnabled: "false"
  #Number of days to retain minute metrics
  blobDiagnosticMinuteMetricsRetentionDays: 10    
    #"true" or "false" strings.  Defaults to "true" if unspecified.
  blobDiagnosticLoggingEnabled: "true"
  #Number of days to retain minute metrics
  blobDiagnosticLoggingRetentionDays: 10    
recipe:
  mypkg-storage:
    properties:
      type: "@azbake/ingredient-storage"
      source: ""
      parameters:
        storageAccountName: "[storage.create_resource_name()]"
parameterrequireddefaultdescription
storageAccountNameyesName for the storage account resource
storageKindnoStorageV2Sets the storage account kind
storageTiernoStandardSets the pricing tier for the storage account
locationnoParent resource group geographic locationThe location for this resource
storageAccountTypenoThe type for the storage account See documentation
storageAccessTiernoSelects Hot or Cold tiers for the storage account. See documentation
containeryes (when source is populated)Container to upload the specific source to. Only used when source is specified.
uploadPathyes (when source is populated)Path within the specified container to upload the source to. Only used when source is specified.
deploynotrueFlag to determine whether or not to deploy the service account. Useful for skipping deployment when just adding context to a container via source
unzipnofalseFlag to determine whether or not to unzip and upload if a zip file is encountered in the specified path.
rgOverridenoSpecifics a resource group override for the storage account if different from the main resource group of the bake recipe.
allowBlobPublicAccessnofalse (secure-by-default baseline flip)Optional. When omitted or false, deploys the account with anonymous public blob access disabled. When true, enables it AND stamps the approved-exception tag hchb-policy-exempt-anon-blob = true. BREAKING CHANGE: As of this version, the baseline is explicit false (property is written); prior versions left the property unwritten (backward compatible with nothing). Recipes relying on the account to maintain its existing anonymous-access state after redeployment must now explicitly set allowBlobPublicAccess: true if that state is true.
allowPublicNetworkAccessno(unset — tag-only stub, property not written)Optional (Pass-1 stub). When true, stamps the approved-exception tag hchb-policy-exempt-public-network = true; the publicNetworkAccess property itself is not written in this pass. When false or omitted, no tag and no property are written. See Public network access.
variablerequireddefaultdescription
blobDiagnosticHourlyMetricsEnabledno"true"Enables recording of hourly metrics to Storage Analytics. Currently accepts "true" / "false" as strings only.
blobDiagnosticHourlyMetricsRetentionDaysno10Data retention of hourly metrics in Storage Analytics.
blobDiagnosticMinuteMetricsEnabledno"true"Enables recording of minute metrics to Storage Analytics. Currently accepts "true" / "false" as strings only.
blobDiagnosticMinuteMetricsRetentionDaysno10Data retention of minute metrics in Storage Analytics
blobDiagnosticLoggingEnabledno"true"Enables recording of diagnostic logs to Storage Analytics. Currently accepts "true" / "false" as strings only.
blobDiagnosticLoggingRetentionDays10"true"Data retention of diagnostic logs in Storage Analytics

*** Please note that the only value required for creation of this resource is the storageAccountName

Anonymous public blob access

The optional allowBlobPublicAccess parameter controls whether the storage account permits anonymous (unauthenticated) public read access to blob data.

BASELINE FLIP (Breaking Change): As of this version, the secure-by-default baseline has changed:

  • Old behavior (Pass-1): Omitting allowBlobPublicAccess left the property unwritten, preserving the account's existing anonymous-access state.
  • New behavior (Pass-2): Omitting allowBlobPublicAccess now writes an explicit false, disabling anonymous public blob access by default.

Impact: If your recipe redeploys an existing storage account and relies on maintaining its current anonymous-access state (if true), you must now explicitly set allowBlobPublicAccess: true in the recipe to preserve that state.

  • Omitted or false: deploys the account with anonymous public blob access disabled. No exception tag is applied. This is the new secure-by-default baseline.
  • true: allows anonymous public blob access to be configured (actual anonymous reads still depend on each container's public-access level) and stamps the approved-exception tag hchb-policy-exempt-anon-blob = true on the account, marking it as a sanctioned exception to the anonymous-blob deny policy. Existing tags (such as Metrics) are preserved.
recipe:
  mypkg-storage:
    properties:
      type: "@azbake/ingredient-storage"
      parameters:
        storageAccountName: "[storage.create_resource_name()]"
        allowBlobPublicAccess: false   # disable anonymous blob access (secure baseline)
        # OR omit allowBlobPublicAccess entirely—it defaults to false

ARM Template Compatibility:

  • storage.json uses apiVersion 2020-08-01-preview — ✓ fully supports allowBlobPublicAccess
  • storageNetwork.json uses apiVersion 2019-06-01 — ✓ supports allowBlobPublicAccess (GA'd in 2019-04-01)
  • storageDatalake.json uses apiVersion 2018-02-01 — ⚠️ predates allowBlobPublicAccess (2019-04-01); the property may be silently ignored by ARM, though the tag still stamps. For datalake accounts (IsHnsEnabled), verify deployment behavior on the target Azure environment before relying on the property being enforced.

Public network access (Pass-1 stub — tag only)

The optional allowPublicNetworkAccess parameter is a forward-compatible stub. In this pass it stamps an approved-exception tag only; it deliberately does not write the storage account's publicNetworkAccess property, so no network behavior changes yet.

  • Omitted (default): nothing is written — no tag, no property. Fully backward compatible.
  • false: no tag is stamped and no property is written (Pass-1 stub — the publicNetworkAccess property is deferred).
  • true: stamps the approved-exception tag hchb-policy-exempt-public-network = true on the account, marking it as a sanctioned exception to the public-network-access deny policy. Existing tags (such as Metrics) are preserved, and this tag co-exists with hchb-policy-exempt-anon-blob (the CDN case).

Deferred enforcement: the boolean will later map to publicNetworkAccess Enabled/Disabled (with private endpoints) in Feature 698027, behind the NetOps private-DNS gate (Feature 701425) — with no further recipe edit required. Setting the property before that DNS enabler exists would sever connectivity, which is why Pass 1 is tag-only.

recipe:
  mypkg-storage:
    properties:
      type: "@azbake/ingredient-storage"
      parameters:
        storageAccountName: "[storage.create_resource_name()]"
        allowPublicNetworkAccess: true   # stamp the exception tag only (no property yet)

Uploading Files to Blob Storage

Files can be uploaded to a blob container during deployment by specifying the source property within the recipe. The source property supports pointing to a direct file via file:/// syntax or pointing to a directory using relative pathing.

NOTE: only blob storage is supported at this time.

name: My package
shortName: mypkg
version: 0.0.1
ingredients:
  - "@azbake/ingredient-storage@~0"
parallelRegions: false
resourceGroup: false
recipe:
  mypkg-storage:
    properties:
      type: "@azbake/ingredient-storage"
      source: "file:///./deploy/deploy.zip" # "./deploy"
      parameters:
        storageAccountName: "[storage.create_resource_name()]"
        container: myContainer
        uploadPath: mypkg/__build_buildNumber__
        deploy: false
        unzip: true

Utilities

Utility classes can be used inside of the bake.yaml file for parameter and source values.

storage class

functiondescription
create_resource_name()Returns the name created for the traffic manager profile when deployed.
add_delete_policy(name, enabled, daysAfter, options?)Creates a delete policy rule with optional container/path/tag filters.
create_policy(...rules)Creates a management policy schema from one or more rules.
get_container(account, container, accessLevel?, policy?)Gets or creates a container and optionally applies a management policy.
get_storageaccount(resourceGroup, name)Gets storage account details including endpoints and key.
get_primary_key(name, rg?)Gets the primary access key for a storage account.
get_secondary_key(name, rg?)Gets the secondary access key for a storage account.
get_primary_connectionstring(name, rg?)Gets the primary connection string for a storage account.
get_secondary_connectionstring(name, rg?)Gets the secondary connection string for a storage account.

Function Details

create_resource_name()

Gets the name create for the traffic manager profile deployed.

...
parameters:
    storageAccountName: "[storage.create_resource_name()]"
...

Returns

string

Lifecycle Management Policies

The storage ingredient supports Azure Blob Storage lifecycle management policies for automatic blob deletion based on age. You can apply policies globally, per container, or even per path prefix.

add_delete_policy(name, enabled, daysAfter, options?)

Creates a delete policy rule for blob lifecycle management. Supports global policies (all blobs), container-level, path-level, or tag-based filtering.

ParameterTypeDescription
namestringThe name of the policy rule (unique within the policy, up to 256 alphanumeric characters)
enabledbooleanWhether the rule is enabled
daysAfternumberDays after last modification to delete the blob
optionsobjectOptional. Filtering options for container/path/tag-based policies
options.prefixMatchstring[]Optional. Array of prefix strings (e.g., ["logs/", "data/temp/"]). Each prefix must start with a container name. Up to 10 prefixes per rule.
options.blobIndexMatchobject[]Optional. Array of blob index tag conditions { name, op, value }
options.blobTypesstring[]Optional. Blob types. Defaults to ["blockBlob"]. Valid: "blockBlob", "appendBlob"

Example: Global delete policy (all blobs)

// Delete all blockBlobs in the storage account after 90 days
const globalRule = storage.add_delete_policy("delete-all", true, 90);

Example: Container-level TTL

// Delete blobs in 'logs' container after 30 days
const logsRule = storage.add_delete_policy("delete-logs", true, 30, { prefixMatch: ["logs/"] });

// Delete blobs in 'temp' container after 7 days  
const tempRule = storage.add_delete_policy("delete-temp", true, 7, { prefixMatch: ["temp/"] });

// Delete blobs in 'archive' container after 365 days
const archiveRule = storage.add_delete_policy("delete-archive", true, 365, { prefixMatch: ["archive/"] });

// Create combined policy
const policy = storage.create_policy(logsRule, tempRule, archiveRule);

Example: Path-level TTL within a container

// Delete blobs in 'data/temp/' after 7 days, 'data/cache/' after 14 days
const tempRule = storage.add_delete_policy("delete-data-temp", true, 7, { prefixMatch: ["data/temp/"] });
const cacheRule = storage.add_delete_policy("delete-data-cache", true, 14, { prefixMatch: ["data/cache/"] });

const policy = storage.create_policy(tempRule, cacheRule);

Example: Filter by blob index tags

// Delete blobs tagged as "archived" in 'reports' container after 14 days
const rule = storage.add_delete_policy("delete-archived-reports", true, 14, {
  prefixMatch: ["reports/"],
  blobIndexMatch: [{ name: "status", op: "==", value: "archived" }]
});

Example: Include appendBlobs

// Delete both blockBlobs and appendBlobs in 'logs' container after 30 days
const rule = storage.add_delete_policy("delete-all-types", true, 30, { 
  prefixMatch: ["logs/"],
  blobTypes: ["blockBlob", "appendBlob"] 
});

create_policy(...rules)

Creates a management policy schema from one or more policy rules.

ParameterTypeDescription
rulesManagementPolicyRule[]One or more policy rules created by add_delete_policy

get_container(account, container, accessLevel?, policy?)

Gets or creates a container and optionally applies a management policy. When a policy is provided, it automatically scopes the policy rules to the specified container by adding prefix filters.

ParameterTypeDescription
accountBakeStorageAccountStorage account object from get_storageaccount()
containerstringContainer name
accessLevelstringOptional. Access level: "container", "blob", or undefined
policyManagementPolicySchemaOptional. Policy to apply (rules will be scoped to this container)

版本与发布记录

@azbake/ingredient-storage 共发布 75 个版本,首次发布于 2019/03/07;过去 12 个月发布了 7 个版本。

版本发布日期距今
0.6.0latest2026/08/192 个月前
0.5.12026/07/233 个月前
0.5.02026/07/223 个月前
0.4.02026/07/213 个月前
0.3.02026/07/213 个月前
0.2.82026/07/094 个月前

关于 @azbake/ingredient-storage 的常见问题

@azbake/ingredient-storage 是什么?

Ingredient for deploying a storage account

如何安装 @azbake/ingredient-storage?

在项目目录运行 npm install @azbake/ingredient-storage,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@azbake/core(*)、@azure/ms-rest-nodeauth(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@azbake/ingredient-storage 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azbake/ingredient-storage 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@azbake/ingredient-storage 可以商用吗?

@azbake/ingredient-storage 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@azbake/ingredient-storage 的下载量有多少?

根据 npm 官方下载统计,@azbake/ingredient-storage 在 2026/10/08 – 2026/11/06 这 30 天内被下载 4,294 次,日均约 143 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azbake/ingredient-storage 还在维护吗?

最新版本 0.6.0 发布于 2026/08/19(2 个月前);至今共发布 75 个版本,其中过去 12 个月发布了 7 个;首次发布于 2019/03/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。