11using Microsoft . OneFuzz . Service . OneFuzzLib . Orm ;
22using System ;
33using System . Collections . Generic ;
4+ using System . Text . Json . Serialization ;
5+
46using PoolName = System . String ;
7+ using Endpoint = System . String ;
8+ using GroupId = System . Guid ;
9+ using PrincipalId = System . Guid ;
510
611namespace Microsoft . OneFuzz . Service ;
712
8-
913/// Convention for database entities:
1014/// All entities are represented by immutable records
1115/// All database entities need to derive from EntityBase
@@ -15,6 +19,7 @@ namespace Microsoft.OneFuzz.Service;
1519/// the "partion key" and "row key" are identified by the [PartitionKey] and [RowKey] attributes
1620/// Guids are mapped to string in the db
1721
22+
1823public record Authentication
1924(
2025 string Password ,
@@ -168,3 +173,102 @@ String InstanceName
168173// colocate: Optional[bool]
169174// ): EntityBase();
170175
176+
177+ public record AzureSecurityExtensionConfig ( ) ;
178+ public record GenevaExtensionConfig ( ) ;
179+
180+
181+ public record KeyvaultExtensionConfig (
182+ string KeyVaultName ,
183+ string CertName ,
184+ string CertPath ,
185+ string ExtensionStore
186+ ) ;
187+
188+ public record AzureMonitorExtensionConfig (
189+ string ConfigVersion ,
190+ string Moniker ,
191+ string Namespace ,
192+ [ property: JsonPropertyName ( "monitoringGSEnvironment" ) ] string MonitoringGSEnvironment ,
193+ [ property: JsonPropertyName ( "monitoringGCSAccount" ) ] string MonitoringGCSAccount ,
194+ [ property: JsonPropertyName ( "monitoringGCSAuthId" ) ] string MonitoringGCSAuthId ,
195+ [ property: JsonPropertyName ( "monitoringGCSAuthIdType" ) ] string MonitoringGCSAuthIdType
196+ ) ;
197+
198+ public record AzureVmExtensionConfig (
199+ KeyvaultExtensionConfig ? Keyvault ,
200+ AzureMonitorExtensionConfig AzureMonitor
201+ ) ;
202+
203+ public record NetworkConfig (
204+ string AddressSpace ,
205+ string Subnet
206+ )
207+ {
208+ public NetworkConfig ( ) : this ( "10.0.0.0/8" , "10.0.0.0/16" ) { }
209+ }
210+
211+ public record NetworkSecurityGroupConfig (
212+ string [ ] AllowedServiceTags ,
213+ string [ ] AllowedIps
214+ )
215+ {
216+ public NetworkSecurityGroupConfig ( ) : this ( Array . Empty < string > ( ) , Array . Empty < string > ( ) ) { }
217+ }
218+
219+ public record ApiAccessRule (
220+ string [ ] Methods ,
221+ Guid [ ] AllowedGroups
222+ ) ;
223+
224+ public record InstanceConfig
225+ (
226+ [ PartitionKey , RowKey ] string InstanceName ,
227+ //# initial set of admins can only be set during deployment.
228+ //# if admins are set, only admins can update instance configs.
229+ Guid [ ] ? Admins ,
230+ //# if set, only admins can manage pools or scalesets
231+ bool AllowPoolManagement ,
232+ string [ ] AllowedAadTenants ,
233+ NetworkConfig NetworkConfig ,
234+ NetworkSecurityGroupConfig ProxyNsgConfig ,
235+ AzureVmExtensionConfig ? Extensions ,
236+ string ProxyVmSku ,
237+ IDictionary < Endpoint , ApiAccessRule > ? ApiAccessRules ,
238+ IDictionary < PrincipalId , GroupId [ ] > ? GroupMembership ,
239+
240+ IDictionary < string , string > ? VmTags ,
241+ IDictionary < string , string > ? VmssTags
242+ ) : EntityBase ( )
243+ {
244+ public InstanceConfig ( string instanceName ) : this (
245+ instanceName ,
246+ null ,
247+ true ,
248+ Array . Empty < string > ( ) ,
249+ new NetworkConfig ( ) ,
250+ new NetworkSecurityGroupConfig ( ) ,
251+ null ,
252+ "Standard_B2s" ,
253+ null ,
254+ null ,
255+ null ,
256+ null )
257+ { }
258+
259+
260+ /// <summary>
261+ /// Check if instance config is valid
262+ /// </summary>
263+ /// <returns>true, [] if instance config is valid;
264+ /// otherwise false, with a list of errors</returns>
265+ public ( bool , List < string > ) CheckInstanceConfig ( )
266+ {
267+ List < string > errors = new ( ) ;
268+ if ( AllowedAadTenants . Length == 0 )
269+ {
270+ errors . Add ( "allowed_aad_tenants must not be empty" ) ;
271+ }
272+ return ( errors . Count == 0 , errors ) ;
273+ }
274+ }
0 commit comments