Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b/316247020 Refactor class structure #226

Merged
merged 57 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f68c2fd
Add RegexJustificationPolicy
jpassing Dec 17, 2023
c3413c7
Add ActivationRequest base class
jpassing Dec 17, 2023
c11fa43
Add Jit/MpaActivationRequest
jpassing Dec 17, 2023
91990a0
Make EntitlementId an abstract base class
jpassing Dec 17, 2023
28dd51b
Add Activator
jpassing Dec 17, 2023
c9c0d12
Move class
jpassing Dec 17, 2023
aec8574
Add catalog
jpassing Dec 17, 2023
fa14f52
Add Activation
jpassing Dec 17, 2023
6b68219
Add Entitlement
jpassing Dec 17, 2023
dfe707a
Add DiscretionaryProjectRoleCatalog
jpassing Dec 17, 2023
9a3da83
Scaffold DiscretionaryProjectRoleCatalog
jpassing Dec 18, 2023
1498d3e
Change accessibility
jpassing Dec 18, 2023
003cf9b
Add tests
jpassing Dec 18, 2023
cae0818
Use Set
jpassing Dec 18, 2023
c04a4e2
Cleanup
jpassing Dec 18, 2023
4b988ff
Provision access
jpassing Dec 18, 2023
b7abf6d
Cleanup
jpassing Dec 18, 2023
a41ca3b
Request validation
jpassing Dec 18, 2023
5a076fa
Scaffold PolicyAnalzer
jpassing Dec 18, 2023
cd37232
Cleanup
jpassing Dec 18, 2023
1f0f676
Cleanup
jpassing Dec 18, 2023
c5452d5
Port project search
jpassing Dec 18, 2023
7064ad7
Add Annotated
jpassing Dec 18, 2023
35034f2
Port listEntitlements
jpassing Dec 18, 2023
cde992c
Port listRoles
jpassing Dec 18, 2023
9f056d8
Port listPeers
jpassing Dec 19, 2023
da03c3a
Remove obsolete field
jpassing Dec 19, 2023
c464580
Port selfApprove
jpassing Dec 19, 2023
2a60267
Log labels
jpassing Dec 19, 2023
4ce2d24
Change Activation
jpassing Dec 19, 2023
8b5af28
Notify
jpassing Dec 19, 2023
86a0ab1
Remove obsolete code
jpassing Dec 19, 2023
6393a22
Remove obsolete code
jpassing Dec 19, 2023
d6aedec
Port getPolicy
jpassing Dec 19, 2023
aee474d
Change label to Requirements
jpassing Dec 19, 2023
b88a624
Add converter
jpassing Dec 19, 2023
90e21a2
Add TokenSigner
jpassing Dec 19, 2023
e8ef3ea
Add tests
jpassing Dec 19, 2023
4f99e9b
Port remaining methods
jpassing Dec 19, 2023
ec4498f
Port remaining methods
jpassing Dec 19, 2023
a6092f2
Remove obsolete classes
jpassing Dec 19, 2023
b6965dd
Remove obsolete classes
jpassing Dec 19, 2023
82a0ce7
Fix message format
jpassing Dec 19, 2023
53d2e36
Bump version
jpassing Dec 19, 2023
59a38b3
Add tests
jpassing Dec 20, 2023
dda0b4f
Add tests
jpassing Dec 20, 2023
dfdc404
Add headers
jpassing Dec 20, 2023
01efe0d
Rename package
jpassing Dec 20, 2023
6467ab2
Cleanup
jpassing Dec 20, 2023
82198f1
Delete vs files
jpassing Dec 20, 2023
a01bcd8
Make JitConstraints package-protected
jpassing Dec 20, 2023
c283beb
Move RoleBinding
jpassing Dec 20, 2023
8203f29
Rename to ProjectRoleBinding
jpassing Dec 20, 2023
b710c07
Cleanup
jpassing Dec 20, 2023
202e45f
Cleanup
jpassing Dec 20, 2023
2969c8e
Cleanup
jpassing Dec 20, 2023
b7e7d94
Keep message schema
jpassing Dec 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.solutions</groupId>
<artifactId>jitaccess</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
<properties>
<surefire-plugin.version>3.2.3</surefire-plugin.version>
<maven.compiler.target>17</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Google LLC
// Copyright 2023 Google LLC
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
Expand All @@ -23,35 +23,19 @@

import com.google.common.base.Preconditions;

import java.util.List;
import java.util.Collection;
import java.util.Set;

/**
* Result list of T with an optional set of warnings.
* @param items collection of items
* @param warnings warnings encountered
*/
public class AnnotatedResult<T> {
/**
* List of bindings. Might be incomplete if Warnings is non-empty.
*/
private final List<T> items;

/**
* Non-fatal issues encountered. Use a set to avoid duplicates.
*/
private final Set<String> warnings;

public AnnotatedResult(List<T> roleBindings, Set<String> warnings) {
Preconditions.checkNotNull(roleBindings);

this.items = roleBindings;
this.warnings = warnings;
}

public List<T> getItems() {
return this.items;
}

public Set<String> getWarnings() {
return warnings;
public record Annotated<TColl extends Collection<?>>(
TColl items,
Set<String> warnings
) {
public Annotated {
Preconditions.checkNotNull(items, "items");
Preconditions.checkNotNull(warnings, "warnings");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private Exceptions() {}
public static String getFullMessage(Throwable e) {
var buffer = new StringBuilder();

for (var exception = e; e != null; e = e.getCause()) {
for (; e != null; e = e.getCause()) {
if (buffer.length() > 0) {
buffer.append(", caused by ");
buffer.append(e.getClass().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
// under the License.
//

package com.google.solutions.jitaccess.core.entitlements;
package com.google.solutions.jitaccess.core;

import com.google.common.base.Preconditions;
import com.google.solutions.jitaccess.core.ProjectId;

import java.util.Comparator;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright 2023 Google LLC
//
// 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.
//

package com.google.solutions.jitaccess.core.catalog;

import com.google.common.base.Preconditions;

/**
* Represents a successful activation of one or more entitlements.
*/
public record Activation<TEntitlementId extends EntitlementId>(
ActivationRequest<TEntitlementId> request
) {
public Activation {
Preconditions.checkNotNull(request, "request");
Preconditions.checkArgument(!request.entitlements().isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Copyright 2023 Google LLC
//
// 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.
//

package com.google.solutions.jitaccess.core.catalog;

import com.google.common.base.Preconditions;

import java.security.SecureRandom;
import java.util.Base64;

/**
* Unique ID of an activation.
*/
public record ActivationId(String id) {
public ActivationId {
Preconditions.checkNotNull(id);
}

private static final SecureRandom random = new SecureRandom();

public static ActivationId newId(ActivationType type) {
var id = new byte[12];
random.nextBytes(id);

return new ActivationId(type.name().toLowerCase() + "-" + Base64.getEncoder().encodeToString(id));
}

@Override
public String toString() {
return this.id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//
// Copyright 2023 Google LLC
//
// 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.
//

package com.google.solutions.jitaccess.core.catalog;

import com.google.common.base.Preconditions;
import com.google.solutions.jitaccess.core.UserId;

import java.time.Duration;
import java.time.Instant;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Represents a request for activating one or more entitlements.
*/
public abstract class ActivationRequest<TEntitlementId extends EntitlementId> {
private final ActivationId id;
private final Instant startTime;
private final Duration duration;
private final UserId requestingUser;
private final Set<TEntitlementId> entitlements;
private final String justification;

protected ActivationRequest(
ActivationId id,
UserId requestingUser,
Set<TEntitlementId> entitlements,
String justification,
Instant startTime,
Duration duration
) {

Preconditions.checkNotNull(id, "id");
Preconditions.checkNotNull(requestingUser, "user");
Preconditions.checkNotNull(entitlements, "entitlements");
Preconditions.checkNotNull(justification, "justification");
Preconditions.checkNotNull(startTime);
Preconditions.checkNotNull(startTime);

Preconditions.checkArgument(
!entitlements.isEmpty(),
"At least one entitlement must be specified");

Preconditions.checkArgument(
!duration.isZero() &&! duration.isNegative(),
"The duration must be positive");

this.id = id;
this.startTime = startTime;
this.duration = duration;
this.requestingUser = requestingUser;
this.entitlements = entitlements;
this.justification = justification;
}

/**
* @return unique ID of the request.
*/
public ActivationId id() {
return this.id;
}

/**
* @return start time for requested access.
*/
public Instant startTime() {
return this.startTime;
}

/**
* @return duration of requested activation.
*/
public Duration duration() {
return this.duration;
}

/**
* @return end time for requested access.
*/
public Instant endTime() {
return this.startTime.plus(this.duration);
}

/**
* @return user that requested access.
*/
public UserId requestingUser() {
return this.requestingUser;
}

/**
* @return one or more entitlements.
*/
public Collection<TEntitlementId> entitlements() {
return this.entitlements;
}

/**
* @return user-provided justification for the request.
*/
public String justification() {
return this.justification;
}

public abstract ActivationType type();

@Override
public String toString() {
return String.format(
"[%s] entitlements=%s, startTime=%s, duration=%s, justification=%s",
this.id,
this.entitlements.stream().map(e -> e.toString()).collect(Collectors.joining(",")),
this.startTime,
this.duration,
this.justification);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright 2023 Google LLC
//
// 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.
//

package com.google.solutions.jitaccess.core.catalog;

public enum ActivationType {
/** Entitlement can be activated using self-approval */
JIT,

/** Entitlement can be activated using multi-party approval. */
MPA,

/** Entitlement can no longer be activated. */
NONE
}
Loading