1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//! Google Cloud service support with convenience APIs
//!
//! This module provides Google Cloud signing functionality along with convenience
//! functions for common use cases.
//!
//! ## Credential Access Boundary downscoping
//!
//! [`ServerSideCredentialAccessBoundaryGranter`] performs an STS exchange for
//! every output and is available with the `google` feature. Enable
//! `google-credential-access-boundary-client-side` to use
//! `ClientSideCredentialAccessBoundaryGranter`, which caches intermediary
//! material and generates each downscoped token locally. Callers choose the
//! mode explicitly; there is no implicit fallback between them.
//!
//! A control plane can obtain reusable intermediary material from Google STS and
//! locally generate distinct tokens restricted to selected Cloud Storage buckets
//! or object prefixes:
//!
//! ```no_run
//! # #[cfg(feature = "google-credential-access-boundary-client-side")]
//! # mod credential_access_boundary_example {
//! use std::time::Duration;
//!
//! use reqsign::{Context, Granter, time::Timestamp};
//! use reqsign::google::{
//! ClientSideCredentialAccessBoundaryGranter, CredentialAccessBoundaryGrant,
//! CredentialAccessBoundaryPermissions, TokenCredentialProvider,
//! };
//!
//! # async fn example() -> reqsign_core::Result<()> {
//! let source = TokenCredentialProvider::new("source-oauth-token")
//! .with_expires_at(Timestamp::now() + Duration::from_secs(3600));
//! let grant = CredentialAccessBoundaryGrant::for_object_prefix(
//! "example-bucket",
//! "customer-a/",
//! CredentialAccessBoundaryPermissions::OBJECT_VIEWER,
//! );
//! // The context must be configured with an HttpSend implementation. When the
//! // `default-context` feature is enabled, use `reqsign::default_context()`.
//! let context = Context::new();
//! let downscoped = Granter::new(
//! context,
//! source,
//! ClientSideCredentialAccessBoundaryGranter::new(grant),
//! )
//! .grant(None)
//! .await?;
//! # let _ = downscoped;
//! # Ok(())
//! # }
//! # }
//! ```
// Re-export all Google Cloud signing types
pub use *;
use crate::;
/// Default Google Cloud Signer type with commonly used components
pub type DefaultSigner = ;
/// Create a default Google Cloud signer with standard configuration
///
/// This function creates a signer with:
/// - Default context (with Tokio file reader, reqwest HTTP client, OS environment)
/// - Default credential provider (reads from env vars, service account, metadata server, etc.)
/// - Request signer for the specified service
///
/// # Example
///
/// ```no_run
/// # #[tokio::main]
/// # async fn main() -> reqsign_core::Result<()> {
/// // Create a signer for Google Cloud Storage
/// let signer = reqsign::google::default_signer("storage.googleapis.com");
///
/// // Sign a request
/// let mut req = http::Request::builder()
/// .method("GET")
/// .uri("https://storage.googleapis.com/my-bucket/my-object")
/// .body(())
/// .unwrap()
/// .into_parts()
/// .0;
///
/// signer.sign(&mut req, None).await?;
/// # Ok(())
/// # }
/// ```
///
/// # Customization
///
/// You can customize the signer using the `with_*` methods:
///
/// ```no_run
/// # async fn example() -> reqsign_core::Result<()> {
/// use reqsign::google::{default_signer, StaticCredentialProvider};
///
/// // Example: use a static credential provider with service account JSON
/// let service_account_json = r#"{
/// "type": "service_account",
/// "project_id": "my-project",
/// "private_key_id": "key-id",
/// "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
/// "client_email": "my-service-account@my-project.iam.gserviceaccount.com",
/// "client_id": "123456789",
/// "auth_uri": "https://accounts.google.com/o/oauth2/auth",
/// "token_uri": "https://oauth2.googleapis.com/token"
/// }"#;
///
/// let signer = default_signer("storage.googleapis.com")
/// .with_credential_provider(StaticCredentialProvider::new(service_account_json));
/// # Ok(())
/// # }
/// ```