-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Add AccessManager contracts #4121
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
Changes from 61 commits
1327b8f
b54b922
5a0fd33
ee5de96
6284768
bce3641
223e6af
eafb571
24af159
833f219
0f27739
2ac5aa1
f26c4d3
63f9393
6fecd25
589b5b1
619cc73
1b681a5
48b31c0
b078157
274c04d
082b05c
52f27c8
1285c49
5c7472a
3cc1e73
ae3482d
535ea13
68bb5fa
fa58ec5
6d76058
3447438
1d10639
d875a7b
d517d27
6d33cda
9ed1aef
6adc0d8
0624794
17ec3b6
f9210c5
a54cd10
8af9ca4
2a05bcc
5f22f2d
6a9fbed
0580198
e01e362
cb026bc
76d35da
4069781
80ffd2a
3094d0c
b3a8b1b
8a68322
eeab8cf
ca61e38
8824c31
67e33b6
5f270c7
6f7ac96
7ec5311
82402d2
27807e6
80bc88b
cf4df22
bab4d34
642e279
51aff23
6e3da66
6b56c8f
b7e3b3f
8200986
18e53e2
f94a881
cd8babd
597edc0
ee560d0
33f5ace
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'openzeppelin-solidity': minor | ||
| --- | ||
|
|
||
| `AccessManager`: Added a new contract for managing access control of complex systems in a consolidated location. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./IAuthority.sol"; | ||
|
|
||
| /** | ||
| * @dev This contract module makes available a {restricted} modifier. Functions decorated with this modifier will be | ||
| * permissioned according to an "authority": a contract like {AccessManager} that follows the {IAuthority} interface, | ||
| * implementing a policy that allows certain callers access to certain functions. | ||
| * | ||
| * IMPORTANT: The `restricted` modifier should never be used on `internal` functions, judiciously used in `public` | ||
| * functions, and ideally only used in `external` functions. See {restricted}. | ||
| */ | ||
| contract AccessManaged { | ||
| event AuthorityUpdated(IAuthority indexed oldAuthority, IAuthority indexed newAuthority); | ||
|
||
|
|
||
| IAuthority private _authority; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that is restrictive, but making this immutable would save a non insignificant amount of gas. In the case of proxy/clones created by a factory, would it make sens that all implementation use the same authority? I think yes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You know I hate multiple versions... 😄 The main reason why I left this as a mutable variable is because I think it can be used to freeze the permissions in a contract by moving it off of an AccessManager onto an immutable Authority. We could also implement freezing in the AccessManager itself, by having frozen contract groups in which permissions can't be altered, and whose contracts can't be moved out of that group. I felt that having mutability of the authority at the managed contract was the simpler option, but it's true that it makes it more expensive. I'm open to this discussion though.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This makes sense, but I also think it violates the goal of consolidation. In this way, now a managed contract may have the right to update itself without the Manager's approval. While that still makes sense to me in some cases, I am not sure if a significant share of My opinion here would be to make it immutable since any freezing capability can be handled by the Manager by making it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think this is true. Only the current manager should be able to "eject" a managed contract from itself.
Note that adding a contract in the Closed or Open group doesn't freeze the permissions, because the manager retains the ability to move it outside of the group.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why not? Any We can keep this private, but I have some bad feelings about letting the user "eject" the contract itself even if done deliberately.
I see what you meant, but a previous idea I remember we discussed is suggesting overrides like: function setContractModeOpern(address target) ... override {
require(_cantReopen[target]);
super.setContractModeCustom(target);
}Not sure exactly how this can play out, but I think there might be a setup we may like to explore (eg. not reopening by default unless explicitly stated).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it's fine if the target contract deliberately inserts a custom-gated |
||
|
|
||
| /** | ||
| * @dev Restricts access to a function as defined by the connected Authority for this contract and the | ||
| * caller and selector of the function that entered the contract. | ||
| * | ||
| * [IMPORTANT] | ||
| * ==== | ||
| * In general, this modifier should only be used on `external` functions. It is okay to use it on `public` functions | ||
| * that are used as external entry points and are not called internally. Unless you know what you're oding, it | ||
| * should never be used on `internal` functions. Failure to follow these rules can have critical security | ||
| * implications! This is because the permissions are determined by the function that entered the contract, i.e. the | ||
| * function at the bottom of the call stack, and not the function where the modifier is visible in the source code. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have any concrete recommendations but didn't want to skip saying that I'm concerned about this if a developer is creating a bridge. We should provide at least a way around this issue if the I'll update if I think of something |
||
| * ==== | ||
| */ | ||
| modifier restricted() { | ||
| _checkCanCall(msg.sender, msg.sig); | ||
| _; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Initializes the contract connected to an initial authority. | ||
| */ | ||
| constructor(IAuthority initialAuthority) { | ||
| _setAuthority(initialAuthority); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns the current authority. | ||
| */ | ||
| function authority() public view virtual returns (IAuthority) { | ||
| return _authority; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Transfers control to a new authority. The caller must be the current authority. | ||
| */ | ||
| function setAuthority(IAuthority newAuthority) public virtual { | ||
| require(msg.sender == address(_authority), "AccessManaged: not current authority"); | ||
frangio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _setAuthority(newAuthority); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Transfers control to a new authority. Internal function with no access restriction. | ||
| */ | ||
| function _setAuthority(IAuthority newAuthority) internal virtual { | ||
| IAuthority oldAuthority = _authority; | ||
| _authority = newAuthority; | ||
| emit AuthorityUpdated(oldAuthority, newAuthority); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Reverts if the caller is not allowed to call the function identified by a selector. | ||
| */ | ||
| function _checkCanCall(address caller, bytes4 selector) internal view virtual { | ||
| require(_authority.canCall(caller, address(this), selector), "AccessManaged: authority rejected"); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.